Installations
npm install node-config-loader
Developer Guide
Typescript
No
Module System
N/A
Node Version
7.6.0
NPM Version
4.1.2
Score
68.3
Supply Chain
96.3
Quality
73.7
Maintenance
100
Vulnerability
98.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (83.33%)
Shell (16.67%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
zerkalica
Download Statistics
Total Downloads
36,994
Last Day
2
Last Week
41
Last Month
130
Last Year
1,069
GitHub Statistics
5 Stars
163 Commits
5 Forks
4 Watching
1 Branches
3 Contributors
Bundle Size
244.78 kB
Minified
61.81 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.1.0
Package Id
node-config-loader@3.1.0
Size
19.36 kB
NPM Version
4.1.2
Node Version
7.6.0
Total Downloads
Cumulative downloads
Total Downloads
36,994
Last day
0%
2
Compared to previous day
Last week
-14.6%
41
Compared to previous week
Last month
202.3%
130
Compared to previous month
Last year
-45%
1,069
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Node config loader
Scan directories, load, parse to js object and merge many configs into single file/object.
- Highly customizable and composable: each component is a pure function and exposed to public: compose you own loaders
- Used globby for files matching
- Compatible with lorenwest node-config file loading scheme, but each file name can be prefixed by '#' separator
- Default loader supports json and yml files via nodeca js-yaml (can be overrided)
- Live reload support via webpack loader
Config merge example
1# input1#dev.yaml 2ns: 3 to: 4 name: test 5testArr: 6 - t1 7 - t2 8__push__: [testArray2] 9testArray2: 10 - test1 11 - test2
1# input2#dev.yaml 2 3ns: 4 to: 5 email: test-email 6testArr: 7 - t3 8testArray2: 9 - test3
merged input1 + input2:
1#output.yaml 2 3ns: 4 to: 5 name: test 6 email: test-email 7testArr: 8 - t3 9testArray2: 10 - test1 11 - test2 12 - test3
Usage
As common lib
1//simple.js
2import {loadConfig} from 'node-config-loader'
3import os from 'os'
4
5loadConfig({
6 mask: [
7 `${__dirname}/config/**/*.{json,yml,tml}`
8 `/etc/myapp.d/**/*.{json,yml,tml}`
9 `${process.env.HOME}/.config/myapp/**/*.{json,yml,tml}`
10 ],
11 instance = 'server',
12 env = process.env.NODE_ENV,
13 hostname = os.hostname(),
14 tagSeparator = '#'
15})
16 .then(config => console.log(config))
17 .catch(err => config.error(err.message))
As webpack loader
Config load order:
- .configloaderrc
- webpack.config.js configLoader section
- webpack loader query params
1import config from 'node-config-loader/webpack?env=prod&instance=client!./.configloaderrc' 2console.log(config)
Where .configloaderrc is
1{ 2 "mask": [ 3 "{ROOT}/src/config/**/*.json" 4 ], 5 "instance": "client|server", 6 "env": "prod|dev", 7 "hostname" : "host", 8 "tagSeparator": "#" 9}
mask is required, all other params are optional.
Available env vars in mask:
- {ROOT} - project root
- {DIRNAME} - .configloaderrc directory
- {PWD} - process.cwd()
- any process.env variable
Via Webpack config
1// webpack.config.js 2module.exports = { 3 plugins: [ 4 new LoaderOptionsPlugin({ 5 options: { 6 configLoader: { 7 env: isProduction ? 'prod' : 'dev', 8 instance: process.env.APP_INSTANCE || 'client' 9 } 10 } 11 }), 12 ], 13 module: { 14 loaders: [ 15 { 16 test: /.*\.configloaderrc$/, 17 loader: 'node-config-loader/webpack' 18 } 19 } 20}
Flowtype
npm install --save empty
.flowconfig
1[options] 2module.name_mapper='.*\(\.configloaderrc\)' -> 'empty/object'
Isomorphic friendly сlient with run-time config
1// getConfig.js 2import config from '../conf/.configloaderrc' 3import {merge} from 'node-config-loader' 4 5function getRuntimeConfig({settings, location, referrer}) { 6 return { 7 env: { 8 origin: location.origin, 9 hash: location.hash, 10 pathname: location.pathname, 11 search: location.search, 12 referrer: referrer 13 }, 14 config: { 15 debug: settings.debug, 16 sitePrefix: settings.sitePrefix, 17 locale: { 18 lang: settings.locale 19 } 20 } 21 } 22} 23 24export default function getConfig(opts) { 25 return merge(config, getRuntimeConfig(opts)) 26}
1// index.js
2import getConfig from './getConfig'
3
4const config = getConfig({
5 settings: window.settings || {},
6 location: window.location,
7 referrer: document.referrer
8})
9
10// config
11init(config)
interfaces
1// @flow 2 3function merge(objects: Object[]): Object 4function strMap(strs: string, templateArgs: {[id: string]: string}): string 5 6interface CreateScannerOpts { 7 merge?: (acc: Object, src: Object) => Object; 8 parser?: (data: FileRec) => Promise<Object>; 9 readFile?: (fileName: string) => Promise<Buffer>; 10} 11 12type Scanner = (files: string[]) => Promise<Object> 13 14function createScanner(opts?: CreateScannerOpts): Scanner 15 16interface CreateNodeFilterOpts { 17 instance?: string; 18 hostname?: string; 19 tagSeparator?: string; 20 env?: string; 21 templates?: string[]; 22} 23function createNodeFilter(opts: CreateNodeFilterOpts): (files: string[]) => string[] 24 25interface GetFilesOptions extends CreateNodeFilterOpts { 26 mask: string[]; 27 glob?: { 28 cwd?: string; 29 root?: string; 30 dot?: string; 31 nomount?: boolean; 32 mark?: boolean; 33 nosort?: boolean; 34 stat?: boolean; 35 readdir?: boolean; 36 silent?: boolean; 37 statCache?: Object; 38 symlinks?: Object; 39 debug?: boolean; 40 nonull?: boolean; 41 nounique?: boolean; 42 nobrace?: boolean; 43 noglobstar?: boolean; 44 noext?: boolean; 45 nocase?: boolean; 46 matchBase?: boolean; 47 nodir?: boolean; 48 ignore?: string; 49 follow?: boolean; 50 realpath?: boolean; 51 absolute?: boolean; 52 } 53} 54function getFiles(opts: GetFilesOptions): Promise<string[]>; 55 56interface LoadConfigOptions extends GetFilesOptions, CreateScannerOpts { 57 mask: string[]; 58 59 instance?: string; 60 hostname?: string; 61 tagSeparator?: string; 62 env?: string; 63 templates?: string[]; 64 65 glob?: Object; 66 67 merge?: (acc: Object, src: Object) => Object; 68 parser?: (data: FileRec) => Promise<Object>; 69 readFile?: (fileName: string) => Promise<Buffer>; 70} 71function loadConfig(opts: LoadConfigOptions): Promise<Object>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
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