Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A developer-friendly lightweight replacement for the 'config' module that works with custom config directory and pluggable parsers
A developer-friendly lightweight replacement for the config
module that works with custom config directory and pluggable parsers.
Notice of change of ownership: Starting version 3.0.0 this package has changed it's owner and goals. The old version (2.0.3) is still available on npm via npm install configly@2.0.3
and on github.com/ksmithut/configly. Thank you.
$ npm install --save configly
Original config
module is convenient and easy to start with library, but in the same time being focused that much on "easy" it lacks certain features to be a "developer friendly" library.
This package is addressing those issues, while keeping easy of use and featureset on par with the original module.
To simply replace your current config
setup, add following to your files:
var config = require('configly')();
console.log(config.my.combined.options);
It will load .js
and .json
files from ./config
folder,
relative to the current working directory (process.cwd()
).
It will cache the result, so files will be read only once per process.
Out of the box configly
supports only two formats (.js
and .json
), but developers can add their own parsers and support for more formats (e.g. .ini
, .yaml
, .cson
).
var config = require('configly');
// more parsers
var ini = require('ini');
var cson = require('cson');
var yaml = require('js-yaml');
var properties = require('properties');
var json5 = require('json5');
// assemble new parsers list
// order doesn't matter since they
// will be alphabetically sorted
config.PARSERS = {
ini : ini.parse,
// have it as a wrapper to prevent extra arguments leaking
cson : function(str) { return cson.parse(str); },
yml : function(str) { return yaml.safeLoad(str); },
// same options as used within `config` module
properties: function(str) { return properties.parse(str, {namespaces: true, variables: true, sections: true}); },
// use json5 instead of `JSON.parse`
json : json5.parse
// keep the original one
js : config.PARSERS.js,
};
var configObj = config();
Since configly
is a singleton, this setup could be done in your index file,
and the rest of the files would use it the same way as in the "Basic" example.
To load config files from a custom directory, just specify it as the first argument.
var config = require('configly')('./etc'); // `require('configly')('./etc');` would work the same way`
It will load files from the etc
folder relative to the current working directory,
by providing absolute path, you can make sure exact location of the config files,
which is useful to libraries meant to be used within larger applications
and for command line apps that could be invoked from different directories.
var path = require('path');
var config = require('configly')(path.join(__dirname, 'etc'));
Or you can set up new directory as default one
and invoke configly
without custom arguments
from within other files.
// index.js
var path = require('path');
var configly = require('configly');
configly.DEFAULTS.directory = path.join(__dirname, 'etc');
// app.js
var config = require('configly')();
It is possible to load files from more than one config directory within one application/module.
var path = require('path');
var ini = require('ini');
var configly = require('configly');
var appConfig = configly(path.join(__dirname, 'app-config'));
// for example you have .ini config files there
var rulesConfig = configly(path.join(__dirname, 'rules-config'), {ini: ini.parse});
If there is a need to merge standalone config objects into one,
you can use configly.merge
method manually,
in the order that suites your specific use case.
var oneConfig = configly.merge(appConfig, rulesConfig);
For more examples check out test directory.
Main differences between configly
and config
:
custom-environment-variables
works via this mechanism)."endpoint": "${REMOTE_HOST}:${REMOTE_PORT}"
).NODE_CONFIG
environment variable.get
, has
methods, it returns pure js object.configly.PARSERS['json'] = json5.parse;
.Configly is licensed under the MIT license.
FAQs
A developer-friendly lightweight replacement for the 'config' module that works with custom config directories and pluggable parsers
The npm package configly receives a total of 411 weekly downloads. As such, configly popularity was classified as not popular.
We found that configly 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.