Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Zero configuration config module. Simply require the module and your project's config files will be loaded and merged together.
A default
configuration file is looked for and loaded first, followed by an
environment level config file, based on NODE_ENV
. Lastly a local
config file
is loaded. All configuration files are recursively extended into any previously
loaded file.
Both .js
and .json
extentions will be loaded.
The local
file is the last on the list to give you the flexibility of having per
user configs, this file is generally included in your .gitignore
to provide
flexibility on the end developer. This could also be used as part of a deployment
strategy if you don't want to rely on NODE_ENV
based settings. Simply copy or
move the file you want, lets say config/production.json
, into config/local.json
to ensure the correct app configuration reguardless of your environment variables.
There are plenty of other configuration modules out there, so why another one?
I wanted a config module that I didn't have to configure, with many others you
will end up including the module, telling it where your files live, and / or
providing it defaults. You might just end up with a config.js
file as a wrapper
to the module of your choosing, too much work I say! This is meant to be an
extremely simple way of configuring your app, all while having a local
config
in mind, which can be very useful when a team is working on the same project.
var config = require('configs')
Config files will be be loaded with the following pattern, pathing is relative
to the project root directory. The project root directory is found by following
the module.parent
recursively until there either is no more parents or a
package.json
file is found.
Directory based:
File based:
In ./config/default.json
:
{
"debug": false
, "database": {
"host": "localhost"
, "port": 6379
, "user": "paul"
}
}
In ./config/local.json
:
{
"debug": true
, "database": {
"port": 11212
}
}
End result: require('configs')
{
"debug": true
, "database": {
"host": "localhost"
, "port": 11212
, "user": "paul"
}
}
If only a single configuration file is found, the module will check for a property
matching the current NODE_ENV
and extend it into the base config.
In ./config.json
{
"something": true
, "sea": {
"lab": 2021
}
, "production": {
"something": false
, "hey": "there"
}
}
With NODE_ENV=production
, require('configs')
"something": false
, "hey": "there"
, "sea": {
"lab": 2021
}
, "production": {
"something": false
, "hey": "there"
}
}
If a debug
property is found after all files have been loaded, the module
will output the file paths of everything that was loaded.
If a package.json
is found within the root directory, the version
property
will be added to the config. The module will also check for a config
property
that can be used to specify the directory in which the files are located. Defaults
to ./config
With npm
npm install configs
(The MIT License)
Copyright (c) 2011-2012 Beau Sorensen mail@beausorensen.com
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
Super simple project configuration
We found that configs 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.