Skip to content

Commit b32ffaa

Browse files
author
bonnel-n
committed
feat: initial commit
0 parents  commit b32ffaa

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Nicolas Bonnel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Diff for: README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Node Environment Configuration
2+
This module provides a way to easily override parts of a JS/JSON configuration file
3+
with environment variables. This module uses [merge-env](https://github.com/bholloway/merge-env) and filters
4+
environment variables prefixed with `NEC_`.
5+
6+
Keys which are **uppercase alpha-numeric**, with possible **underscore**, are legal environment variables per IEEE Std 1003.1-2001 Shell and Utilities volume. These keys are assumed to describe camel-case fields where single underscore implies camel-case, and double underscore implies a dot (i.e. nested object). Their value must be some non-object.
7+
8+
For example:
9+
```
10+
NEC_FOO_BAR = 1
11+
NEC_BAR__BAZ = true
12+
```
13+
14+
gives:
15+
```javascript
16+
{
17+
fooBar: 1,
18+
bar: {
19+
baz: true
20+
}
21+
}
22+
```
23+
24+
## Install
25+
No npm build yet, reference this repository in your package.json file
26+
27+
## Usage
28+
29+
```
30+
var envConfig = require('env-config')
31+
var defaultConfig = require('/path/to/config.js')
32+
var config = envConfig(defaultConfig)
33+
// You can now use your config object
34+
```

Diff for: index.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const merge = require('merge-env')
2+
const pickBy = require('lodash.pickby')
3+
const mapKeys = require('lodash.mapkeys')
4+
5+
var envVars = pickBy(process.env, function(value, key){
6+
return key.startsWith('NEC_')
7+
});
8+
9+
envVars = mapKeys(envVars, function(value, key){
10+
return key.split('NEC_').slice(1).join('_')
11+
})
12+
13+
module.exports = function(config){
14+
return merge(config,envVars)
15+
}

Diff for: package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "env-config",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"lodash.mapkeys": "^4.6.0",
13+
"lodash.pickby": "^4.6.0",
14+
"merge-env": "^1.0.0"
15+
}
16+
}

Diff for: test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
process.env.NEC_FOO_BAR = 3
2+
process.env.NEC_BAR__BAZ = true
3+
4+
var envConfig = require('./index')
5+
var config = envConfig({
6+
fooBar: 1,
7+
fooBar2: 2,
8+
bar: {
9+
baz: false
10+
}
11+
})
12+
13+
console.log(config)

0 commit comments

Comments
 (0)