Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
node-config-manager
Advanced tools
Readme
A configuration manager for NodeJS. It helps you to organize your project and the different configurations of your environments.
npm install --save node-config-manager
In a project, it's often necessary to have multiple environments (test, development, preproduction, production, etc.). ConfigManager offers a simple and intuitive architecture to organize it.
Example :
config/
release/ (release env)
logger.yaml
db.json
develop/ (develop env)
logger.json
db.js
test/ (test env)
db.json
logger.js (default logger configuration)
db.js (default db configuration)
lambda.json (default lambda configuration)
The config directory can be overridden by environment variables (NODE_CONFIG_DIR='./config') or when ConfigManager is initialized (#ConfigManager.prototype.init) .
Name | Type | Default | Description |
---|---|---|---|
NODE_CONFIG_DIR | String | ./config | Config directory path |
NODE_ENV | String | -- | Node environment |
NODE_CAMEL_CASE | Boolean | false | Naming convention of variables |
If you don't like to configure with environment variables, you can initialize the different variables in JavaScript by using prototype init method.
var cfgManager = require('node-config-manager'),
options = {
configDir: './config',
env: 'test',
camelCase: true
};
cfgManager.init(options);
After the configuration of the module, you can use the configuration store everywhere.
In the first step, ConfigManager will search for the config file which matches with the current environment.
Example - test environment :
config/
test/ (test env)
db.json
logger.js (default logger configuration)
db.js (default db configuration)
var cfgManager = require('node-config-manager');
cfgManager.addConfig('db') //Load config/test/db.json
.addConfig('logger'); // Load config/logger.js
In the second step, ConfigManager will replace the loaded configurations by environment variables if they exist.
Example - app.json :
{
"host": "localhost",
"port": 80,
"fstKey": {
"sndKey": "custom_key_1",
"copyHost": "custom_key_2"
}
}
And with the following environment variables :
export APP__HOST="127.0.0.1"
export APP__FST_KEY__SND_KEY="anyKey"
export APP__FST_KEY__COPY_HOST="${APP__HOST}"
Result :
{
"host": "127.0.0.1",
"port": 80,
"fstKey": {
"sndKey": "anyKey",
"copyHost": "127.0.0.1"
}
}
After adding your configuration, there are two methods to get your configuration :
var appCfgByGetConfig = cfgManager.getConfig('app'),
appCfgByMethod = cfgManager.method.App();
console.log(appCfgByGetConfig.host); //127.0.0.1
console.log(appCfgByMethod.port); //80
If the config doesn't exist :
You can delete a configuration with the removeConfig method.
cfgManager.removeConfig('app');
Environment variables cannot be typed. ConfigManager will try to infere the type, for example APP__HOST=127.0.0.1
will be parsed as a string and APP_PORT=8080
as a number.
You can override this type inference with type prefixes in environment variables : APP_PORT=ncm_string:8080
will return a string instead of number. The following type prefixes are supported:
ncm_string
ncm_boolean
ncm_number
From the repo root:
npm install
npm test
FAQs
A configuration manager for NodeJS. It helps you to organize your project and the different configurations of your environments.
The npm package node-config-manager receives a total of 67 weekly downloads. As such, node-config-manager popularity was classified as not popular.
We found that node-config-manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.