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.
config-js
Advanced tools
Readme
A config utility for node.js, that uses a single JavaScript file with an export JavaScript object. After loading the JavaScript object from the configuration file, all properties are set constant, preventing changes. However, if the file is changed on disk, it is automatically reloaded.
There is support for environment targets. If you have the environment variable
NODE_ENV
set and you have '##' in your file path, config.js substitutes the
'##' with the contents of NODE_ENV
and then loads that file. If you have a
file named ./conf/app_PRODUCTION.js
, you would load it like so:
process.env.NODE_ENV = 'PRODUCTION';
var Config = require('config-js');
var config = new Config('./conf/app_##');
config.js uses "have" to validate arguments passed to it. If you pass incorrect arguement types, have will throw. You should not wrap your calls in try/catch handlers, but test the inputs you are using. The logic is, if you are not passing the correct types, it's a bug to fix not a run-time situation to handle.
_
Then the environment variable overrides any
values in the configuration files.$ npm install config-js
The configuration file should export an object via module exports as seen in the following example:
module.exports = {
logging : {
level: 'info', // INFO logging level
name: 'mush.js', // Category name for logging
},
server : { port : 4201 }
};
Using the above configuration file, the following code will not throw an exception:
var Config = require('config-js');
var config = new Config('./test/cfg_example.js');
assert.ok(config.get('server.port') === 4201);
assert.ok(config.get('logging.name') === 'mush.js');
// test default value
assert.ok(config.get('No.Such.Value.Exists', 511) === 511);
assert.ok(config.setSepChr('/') === true);
assert.ok(config.get('server/port') === 4201);
assert.ok(config.get('logging/name') === 'mush.js');
Additionally, the configuration file can have regions:
module.exports = {
en: {
welcome: "Welcome to this file."
},
de: {
welcome: "Willkommen zu dieser datei."
},
es: {
welcome: "Bienvenidos a este archivo."
}
};
The regions can be used with the getByRegion method:
// if no region is specified, 'en' is assumed.
assert.ok(config.getByRegion('welcome') === 'Welcome to this file.');
// You can change the above assumption in the constructor
config = new Config('./test/cfg_example2.js', 'de');
assert.ok(config.getByRegion('welcome') === 'Willkommen zu dieser datei.');
// the get method can still be used
assert.ok(config.get('de.welcome') === 'Willkommen zu dieser datei.');
// and you can always specify the region
assert.ok(config.getByRegion('welcome', 'es') === 'Bienvenidos a este archivo.');
Config provides a simple read-only API to a configuration object.
Loads the configuration from the location specified by the parameter.
Return the value associated with the specified property. If no such property is found, the provided defaultValue will be returned or undefined if no defaultValue was provided.
Return the region-specific value associated with the specified property. If no such property is found, the provided defaultValue will be returned or undefined if no defaultValue was provided. The region should be provided in the constructor to this object. If no region was specified when this object was created, the defaultValue will be returned.
Change the default separator character from '.' to whatever character you want.
The MIT License (MIT)
Copyright (c) 2013,2014 Edmond Meinfelder
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
A simple config module. Support for regions and auto-load when file changes.
The npm package config-js receives a total of 275 weekly downloads. As such, config-js popularity was classified as not popular.
We found that config-js 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.