Comparing version
@@ -33,4 +33,3 @@ var fs = require('fs'); | ||
var env = env_getter(filepath); | ||
var keys = Object.keys(env); | ||
keys.forEach(function(k) { | ||
Object.keys(env).forEach(function(k) { | ||
if(!process.env[k]) { // allow enviroment to take precedence over env.json | ||
@@ -79,3 +78,3 @@ process.env[k] = env[k]; // only set if not set by environment | ||
function add_dot_env_line_to_json (json, env_variable) { | ||
var environment_parts = env_variable.split('=').map(trim); | ||
var environment_parts = env_variable.replace('export','').split('=').map(trim); | ||
json[environment_parts[0]] = environment_parts[1]; | ||
@@ -82,0 +81,0 @@ return json; |
{ | ||
"name": "env2", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Environment Variable Loader", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -40,2 +40,4 @@ env2 - environment variable loader | ||
We call our file `config.env` for *cross-project consistency*. | ||
(*but you can call your file what ever you like e.g*: `.env`) | ||
A `config.env` file is a very explicit way of listing environment variables | ||
@@ -49,9 +51,9 @@ without the extra syntax (_potential human/input error_) of a JSON file. | ||
```sh | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=9200 | ||
DB_USER=anon | ||
DB_PASS=password | ||
export DB_HOST=127.0.0.1 | ||
export DB_PORT=9200 | ||
export DB_USER=anon | ||
export DB_PASS=password | ||
``` | ||
Note the **lack of spaces**. You may leave blank lines and insert comments | ||
> Note the **lack of _spaces_**. You may leave blank lines and insert comments | ||
(starting with '#') to organise the file if you wish. Follow the **instructions | ||
@@ -73,3 +75,3 @@ below** for placing it in your `.gitignore` file. | ||
### Always `.gitignore` your configuration file | ||
### *Always* `.gitignore` your configuration file | ||
@@ -84,3 +86,3 @@ ***Always*** create your `config.env` or `env.json` file | ||
``` | ||
or | ||
***or*** | ||
```sh | ||
@@ -124,3 +126,3 @@ echo 'env.json' >> .gitignore | ||
Do you want the ability to *specify* the priority which | ||
environment variables take precendence? | ||
environment variables take precendence? | ||
e.g: if you supply a command-line argument when running your script/app: | ||
@@ -149,2 +151,3 @@ ```sh | ||
<br /> | ||
@@ -151,0 +154,0 @@ ## Name ? |
var test = require('tape'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var decache = require('decache'); | ||
var envfile = path.resolve(__dirname + '/../env.json'); | ||
var sample = path.resolve(__dirname + '/../env.json_sample'); | ||
var dotenv = path.resolve(__dirname + '/../.env'); | ||
var decache = require('decache'); // | ||
var envfile = path.resolve(__dirname + '/fixtures/env.json'); | ||
// console.log(envfile); | ||
// console.log(' - - - - - - - - - - - '); | ||
// return; | ||
var sample = path.resolve(__dirname + '/fixtures/env.json_sample'); | ||
var dotenv = path.resolve(__dirname + '/fixtures/.env'); | ||
var newenv = path.resolve(__dirname + '/../new.env'); | ||
@@ -44,2 +47,6 @@ var tempenv = './tempenv.json'; | ||
t.ok(!process.env.API_KEY, 'API_KEY is not set (as expected)'); | ||
// delete all environment variables before next test: | ||
Object.keys(process.env).forEach(function(key){ | ||
delete process.env[key]; | ||
}); | ||
t.end(); | ||
@@ -49,3 +56,3 @@ }); | ||
test("Force error by refencing non-existent env.json file", function(t) { | ||
require('../lib/env')('./env.json'); | ||
require('../lib/env')('./node_modules/env.json'); | ||
t.ok(!process.env.API_KEY, 'API_KEY is not set (as expected)'); | ||
@@ -117,1 +124,13 @@ t.end(); | ||
}) | ||
var config = path.resolve(__dirname + '/../config.env'); | ||
require('../lib/env.js')(config); // local | ||
// this ensures that the node_modules condition in lib/env.js is met | ||
test("Confirm that EVERYTHING=AWESOME", function(t) { | ||
t.ok(process.env.EVERYTHING === 'AWESOME', | ||
'Worked! Everything is: '+process.env.EVERYTHING) | ||
t.ok(process.env.BUILD === 'SPACESHIP', | ||
'What do we want to build? ...> '+process.env.BUILD + ' !!! :-)'); | ||
t.end(); | ||
}); |
{ | ||
"DBUSER": 1 | ||
, "DBPASSWORD": 1 | ||
"API_KEY":"secret", | ||
"DBUSER": 1, | ||
"DBPASSWORD": 1 | ||
} |
var test = require('tape'); | ||
var decache = require('decache'); | ||
var path = require('path'); | ||
decache('../lib/env.js'); // delete any previously cached version | ||
decache('../../lib/env.js'); // delete alias from require cache | ||
var env2 = require('../../lib/env.js')('config.env'); // local | ||
var config = path.resolve(__dirname + '/../config.env'); | ||
require('../../lib/env.js')(config); // local | ||
@@ -8,0 +9,0 @@ // this ensures that the node_modules condition in lib/env.js is met |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
35033
1.3%165
1.85%0
-100%13
-23.53%227
-0.87%33
22.22%