Gathering detailed insights and metrics for node-config-loader
Gathering detailed insights and metrics for node-config-loader
Gathering detailed insights and metrics for node-config-loader
Gathering detailed insights and metrics for node-config-loader
npm install node-config-loader
Typescript
Module System
Node Version
NPM Version
68.3
Supply Chain
96.3
Quality
73.7
Maintenance
100
Vulnerability
98.6
License
JavaScript (83.33%)
Shell (16.67%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
36,994
Last Day
2
Last Week
41
Last Month
130
Last Year
1,069
5 Stars
163 Commits
5 Forks
4 Watching
1 Branches
3 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
Scan directories, load, parse to js object and merge many configs into single file/object.
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
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))
Config load order:
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:
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}
npm install --save empty
.flowconfig
1[options] 2module.name_mapper='.*\(\.configloaderrc\)' -> 'empty/object'
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)
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
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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