Gathering detailed insights and metrics for node-config-yaml
Gathering detailed insights and metrics for node-config-yaml
npm install node-config-yaml
Typescript
Module System
Node Version
NPM Version
61.8
Supply Chain
93.5
Quality
72.3
Maintenance
50
Vulnerability
97.6
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
5,110
Last Day
2
Last Week
2
Last Month
39
Last Year
1,253
28 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.4
Package Id
node-config-yaml@0.1.4
Unpacked Size
28.12 kB
Size
7.68 kB
File Count
22
NPM Version
5.6.0
Node Version
9.10.1
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
-60%
2
Compared to previous week
Last month
5.4%
39
Compared to previous month
Last year
97.9%
1,253
Compared to previous year
$ yarn add node-config-yaml
or
$ npm install node-config-yaml
Use config for yaml config files in Node.js projects. For example you might have a project with the following config.yml file in the project dir.
1 2app: 3 url: http://myapp.com/home 4 cache: redis 5 6db: 7 location: mysql-db-prod 8
This config can be accessed like this.
1 2var config = require('node-config-yaml').load(); 3 4console.log(config.app.url); 5console.log(config.app.cache); 6console.log(config.db.location); 7
You can might use:
1 2var config = require('node-config-yaml') 3 4.load() // load config from config.yml in root project directory 5.load('file') // load config from .yml file 6.load('dir') // load all .yml files in directory to config 7.load(['dir', 'file']) // load .yml files from sources to config 8.load(['some_sources'], { root: 'root_file_name' }) // load .yml files from sources to config with root_file_name as root (default: config) 9
You can substitute variables in the config.yml like this.
1 2dns: myapp.com 3 4app: 5 url: http://${dns}/home 6 cache: redis 7 8db: 9 location: mysql-db-prod 10
This config would yield the following.
1 2console.log(config.app.url); 3 4// outputs - http://myapp.com/home 5
Instead of having a file named config.yml
with all of your environment settings in place, you could have a config
folder
at the root level of your project. This module will read in every .yml
file, and return an object that looks like:
1{ 2 [file-name]: [parsed-file-contents], 3 ..., 4}
if you need to do cross-file referencing, you can, via dot-notation:
1# file `a.yml` 2foo: bar
1#file `b.yml` 2baz: ${a.foo}
will get you
1{ 2 a: {foo: 'bar'}, 3 b: {baz: 'bar'} 4}
with root options:
1# file `a.yml` 2foo: bar
1#file `b.yml` 2baz: ${foo}
will get you
1.load(['a.yml', 'b.yml'], { root: 'a' } 2 3{ 4 foo: 'bar', 5 b: {baz: 'bar'} 6}
Based on an Environment ID, you can designate specific override settings for different types of environments. First you have to specify your Environment ID. You can do so in one of several ways. The first Environment ID that is found in the following order wins.
To understand this better let's first talk about Static Environments. These are environments that have their own environment specific settings or Environment Overrides. Not necessarily all environments have their own environment specific settings, but those that do should be defined as Static Environments in the config.yml as follows:
1 2environments: 3 static: 4 - dev 5 - test 6 - prod 7
The other approach you can take is to have top level keys that only consist of your environments.
setup your config.yml as follows:
1dev: 2 # ... 3test: 4 # ... 5prod: 6 # ...
Your filenames determine the keys, so your directory could be set as follows:
config/dev.yml
config/test.yml
config/prod.yml
Set the Environment ID using --env command line argument.
node app.js --env feature-xyz
This is often helpful when running gulp tasks.
gulp deploy --env feature-xyz
For Static Environments set the Environment ID using the static environment id as an argument.
gulp deploy --prod
Set the Environment ID using ENVIRONMENT_ID process environment variable.
export ENVIRONMENT_ID=feature-xyz
If an Environment ID is not found using one of the other methods, it will use the git branch for the current project
folder. This branch can be filtered using regex. Let's say your current branch is Features/ISSUE-123-feature-xyz
,
and you have the following setting in your config.yml.
1 2branchRegex: Features/ISSUE-\d+-((\w|-)+) 3
The Environment ID will be feature-zyz
. If no branchRegex is given the branch name will be taken as is.
The Environment ID can be substituted into the config.yml. Let's say you have an Environment ID feature-xyz
and
the following config.yml.
1dns: ${envId}.myapp.com 2 3app: 4 url: http://${dns}/home 5 cache: redis 6 7db: 8 location: MYSQL-DB-${ENVID}
This will yield the following:
1var config = require('node-config-yaml').load(); 2 3console.log(config.dns); // feature-xyz.myapp.com 4console.log(config.app.url); // http://feature-xyz.myapp.com 5console.log(config.db.location); // MYSQL-DB-FEATURE-XYZ 6
For Static Environments, settings can be overridden for that specific environment. For example, with the following config.yml:
1dns: ${envId}.myapp.com 2 3app: 4 url: http://${dns}/home 5 cache: redis 6 7db: 8 location: MYSQL-DB-${ENVID} 9 10prod: 11 app: 12 url: https://${dns} 13 db: 14 location: DB-${ENVID} 15
and the following app.js file:
1var config = require('node-config-yaml').load(); 2 3console.log(config.dns); 4console.log(config.app.url); 5console.log(config.app.cache); 6console.log(config.db.location); 7
the following command:
node app.js --prod
would output the following:
prod.myapp.com
https://prod.myapp.com
redis
MYSQL-DB-PROD
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
63 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More