Socket
Book a DemoInstallSign in
Socket

config-settings

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-settings

Reading configuration from json file or consul.

2.3.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

config-setttings

build status David deps Test coverage node version

NPM

install

npm install config-settings --save

Usage

Use with JsonConfig

{
    "var":"xxxx",
    "integer":111,
    "dir":"/var/xxx",
    "dirNotExist":"1234567890qwerty",
    "file":"/var/filename",
    "fileDirExist":"/var/filenotexist",
    "fileNotExist":"098987655oiouyuyt",
    "int":11,
    "notInt":"xx",
    "url":"http://baidu.com"
}
const config = require('../config.json');
const {JsonConfig} = require('config-settings');
const jsonConfig = new JsonConfig(config);
var varstr = jsonConfig.loadNecessaryVar('var');//get xxxx
var integer = jsonConfig.loadNecessaryVar('integer');//get 111

Use with ConsulConfig

const {ConsulConfig} = require('config-settings');
const settings = new ConsulConfig({consulAddr:'127.0.0.1:8500'});

settings.loadNecessaryVar('var').then(function(value) {
    const varstr =  value;
});
settings.loadNecessaryVar('integer').then(function(value) {
    const integer =  value;
});
settings.allLoaded().then(function() {
    //all loading progress finished
}).catch(function() {

});

Use the ConsulSyncConfig

const {ConsulSyncConfig} = require('config-settings');
const settings = new ConsulConfig({consulAddr:'127.0.0.1:8500', keys: ['var', 'integer']});

const varstr =  settings.loadNecessaryVar('var');
const integer =  settings.loadNecessaryVar('integer');

Attention

When call the function start with loadNecessary failed, the module will throw Error in asynchronous way.

API

See the document of api

Test

You should set the environment variable of CONSUL_SERVER in format of ip:port before npm run.

License

MIT

Keywords

config

FAQs

Package last updated on 01 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.