environmental
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "environmental", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Provides conventions and code to deal with unix environment vars in a pleasant way", | ||
@@ -11,5 +11,4 @@ "homepage": "https://github.com/kvz/environmental", | ||
"dependencies": { | ||
"flat": "1.2.1" | ||
}, | ||
"devDependencies": { | ||
"flat": "1.2.1", | ||
"chai": "1.9.1", | ||
"coffee-script": "1.7.1", | ||
@@ -23,2 +22,3 @@ "coffeelint": "1.3.0", | ||
"vars", | ||
"unix", | ||
"12factor", | ||
@@ -25,0 +25,0 @@ "nodejitsu", |
@@ -9,3 +9,3 @@ Many people think shipping config json files is an upgrade over environment variables. It's not. | ||
Unix environment vars are ideal for configration and I have yet to encounter an application that woudn't be better of with them. | ||
Unix environment vars are ideal for configration and I have yet to encounter an application that woudn't be better off with them. | ||
@@ -23,18 +23,14 @@ - You can change a value at near-runtime: `DEBUG=*.* node run.js` | ||
Doesn't | ||
Environmental Doesn't | ||
- break [12-factor](http://12factor.net/) | ||
- get in your way | ||
- Break [12-factor](http://12factor.net/) | ||
- Get in your way | ||
Does | ||
Environmental Does | ||
- Impose guidelines on dealing with environments | ||
- Make vars available in nested format inside your app (e.g. MYAPP_REDIS_HOST) becomes config.redis.host | ||
- Impose **one way*** of dealing with environment variables | ||
- Make vars available in nested format inside your app (e.g. `MYAPP_REDIS_HOST`) becomes `config.redis.host` | ||
- Play well with unix | ||
- Interpret multiple inherited bash environment files in an isolated environment for exporting to [Nodejitsu](https://www.nodejitsu.com/documentation/jitsu/env/) or [Heroku](https://devcenter.heroku.com/articles/config-vars) | ||
- Interpret multiple inherited bash environment files in an isolated environment to capture them, and prepare them for exporting to [Nodejitsu](https://www.nodejitsu.com/documentation/jitsu/env/) or [Heroku](https://devcenter.heroku.com/articles/config-vars). | ||
Heroku example | ||
Nodejitsu example | ||
## Conventions | ||
@@ -63,4 +59,4 @@ | ||
This provides DRY flexibilty, but in practice I recommend using mainly | ||
development.sh and production.sh, and duplication keys between them | ||
You could make this super-DRY, but I actually recommend using mainly | ||
`development.sh` and `production.sh`, and duplicate keys between them | ||
so you can easily compare side by side. | ||
@@ -82,1 +78,50 @@ Then just use _default.sh, test.sh, staging.sh for tweaks, to keep things | ||
## Getting started | ||
In a new project, type | ||
```bash | ||
$ npm install --save environmental | ||
``` | ||
This will install the node module. Next you'll want to set up an example environment using these templates: | ||
```bash | ||
cp -Ra node_modules/environmental/envs ./envs | ||
``` | ||
You'll want to add `envs/*.sh` to your project's `.gitignore` file so they are not accidentally committed into your repository. Having env files in Git can be convenient for protoyping, but once you go live you'll want to change all credentails and sync your env files separate from your code. | ||
## Usage inside app | ||
You can also use it inside an app: | ||
```bash | ||
source envs/development.sh && node myapp.js | ||
``` | ||
```javascript | ||
var Environmental = require ('environmental'); | ||
var environmental = new Environmental(); | ||
var config = environmental.nested(process.env, process.env.NODE_APP_PREFIX); | ||
console.log(config); | ||
// Will return | ||
// | ||
// { redis: { host: '127.0.0.1' } } | ||
``` | ||
As you see, any underscore `_` in env var names signifies a new nesting level of configuration, and all keys are lowercased. | ||
## Exporting to Nodejitsu | ||
```bash | ||
$ ./bin/environmental envs/production.sh | ||
{"MYAPP_REDIS_PORT":"6379","NODE_APP_PREFIX":"MYAPP","MYAPP_REDIS_PASS":"","DEPLOY_ENV":"production","SUBDOMAIN":"mycompany-myapp","NODE_ENV":"production","MYAPP_REDIS_HOST":"127.0.0.1","DEBUG":""} | ||
$ ./bin/environmental envs/production.sh > /tmp/jitsu-env.json | ||
$ jitsu --confirm env load /tmp/jitsu-env.json | ||
$ jitsu --confirm deploy | ||
``` | ||
## Exporting to Heroku |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
16073
0
16
124
5
+ Addedchai@1.9.1
+ Addedcoffee-script@1.7.1
+ Addedcoffeelint@1.3.0
+ Addedmocha@1.18.2
+ Added@isaacs/cliui@8.0.2(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedassertion-error@1.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedchai@1.9.1(transitive)
+ Addedcoffee-script@1.7.1(transitive)
+ Addedcoffeelint@1.3.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcommander@0.6.12.0.0(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addeddeep-eql@0.1.3(transitive)
+ Addeddiff@1.0.7(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@11.0.13.2.3(transitive)
+ Addedgraceful-fs@2.0.3(transitive)
+ Addedgrowl@1.7.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@4.0.3(transitive)
+ Addedjade@0.26.3(transitive)
+ Addedlru-cache@11.0.22.7.3(transitive)
+ Addedminimatch@0.2.1410.0.1(transitive)
+ Addedminimist@0.0.10(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedmkdirp@0.3.00.3.5(transitive)
+ Addedmocha@1.18.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addedoptimist@0.6.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@2.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedtype-detect@0.1.1(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwordwrap@0.0.3(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)