![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Simple, environment-based configuration. confit
loads a default JSON
configuration file, additionally loading environment-specific files, if applicable.
It will also process the loaded files using any configured
shortstop protocol handlers.
(See Options below.)
var confit = require('confit');
options
(String | Object) - the base directory in which config files live or a configuration object. If no
arguments is provided, defaults to the directory of the calling file. Signature function (err, config) {}
'use strict';
var path = require('path');
var confit = require('confit');
var basedir = path.join(__dirname, 'config');
confit(basedir).create(function (err, config) {
config.get; // Function
config.set; // Function
config.use; // Function
config.get('env:env'); // 'development'
});
addOverride(filepath)
- Register a file (JSON or JS), the contents of which should be merged with the config datastore.create(callback)
- Creates the config object, ready for use. Callback signature: function (err, config) {}
// All methods besides `create` are chainable
confit(options)
.addOverride('./mysettings.json')
.addOverride('./mysettings.json')
.create(function (err, config) {
// ...
});
// - or -
//
// var factory = confit(options);
// factory.addOverride('./mysettings.json');
// factory.create(function (err, config) {
// // ...
// });
basedir
(String) - the base directory in which config files can be found.protocols
(Object) - An object containing a mapping of
shortstop protocols to handler implementations.
This protocols will be used to process the config data prior to registration.defaults
(String) - the name of the file containing all default values.
Defaults to config.json
.'use strict';
var path = require('path');
var confit = require('confit');
var handlers = require('shortstop-handlers');
var options = {
basedir: path.join(__dirname, 'config');
protocols: {
file: handlers.file,
glob: handlers.glob
}
};
confit(options).create(function (err, config) {
// ...
});
get(key)
- Retrieve the value for a given key. Colon-delimited keys can be used to traverse the object hierarchy.set(key, value)
- Set a value for the given key. Colon-delimited keys can be used to traverse the object hierarchy.use(obj)
- merge provided object into config.config.set('foo', 'bar');
config.get('foo'); // 'bar'
config.use({ foo: 'baz' });
config.get('foo'); // 'baz'
config.use({ a: { b: { c: 'd' } } } );
config.get('a:b:c'); // 'd'
By default, confit
loads process.env
and argv
values upon initialization. Additionally,
it creates convenience environment properties prefixed with env:
based on the
current NODE_ENV
setting, defaulting to development
. It also normalizes
NODE_ENV
settings to the long form, so dev
becomes development
, prod
becomes production
, etc.
// NODE_ENV='dev'
config.get('NODE_ENV'); // 'dev'
config.get('env:env'); // 'development'
config.get('env:development'); // true
config.get('env:test'); // false
config.get('env:staging'); // false
config.get('env:production'); // false
// NODE_ENV='custom'
config.get('NODE_ENV'); // 'custom'
config.get('env:env'); // 'custom'
config.get('env:development'); // false
config.get('env:test'); // false
config.get('env:staging'); // false
config.get('env:production'); // false
config.get('env:custom'); // true
FAQs
Environment-aware configuration.
The npm package confit receives a total of 3,658 weekly downloads. As such, confit popularity was classified as popular.
We found that confit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.