Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
nohup.out
npm-debug.log
node_modules
/coverage
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- 0.6
- 0.12
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Env - In your environment managing your variables.
===

[![Build Status](https://secure.travis-ci.org/dshaw/env.png)](http://travis-ci.org/dshaw/env)
[![Build Status](https://travis-ci.org/dwyl/env.svg)](https://travis-ci.org/dwyl/env)
[![Test Coverage](https://codeclimate.com/github/dwyl/env/badges/coverage.svg)](https://codeclimate.com/github/dwyl/env/coverage)
[![Code Climate](https://codeclimate.com/github/dwyl/env/badges/gpa.svg)](https://codeclimate.com/github/dwyl/env)
[![Dependency Status](https://david-dm.org/dwyl/env.svg)](https://david-dm.org/dwyl/env)
[![devDependency Status](https://david-dm.org/dwyl/env/dev-status.svg)](https://david-dm.org/dwyl/env#info=devDependencies)
[![npm](https://img.shields.io/npm/v/env.svg)](https://www.npmjs.com/package/env)

Managing environment variables can be a pain. Env helps make that better.

Expand Down
1 change: 1 addition & 0 deletions env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 5 additions & 4 deletions lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Module dependencies
*/

var path = require('path')
var path = require('path'); // path.existsSync is depracated
var fs = require('fs'); // using fs.statSync instead for same check

/**
* Exports
Expand All @@ -21,8 +22,8 @@ exports = module.exports = createEnv;
*/

function Env (envfile) {
this.envfile = path.join(process.cwd(), envfile || 'env.json')
this.evars = (path.existsSync(this.envfile)) ? require(this.envfile) : {}
this.envfile = envfile || path.resolve(process.cwd() + '/env.json');
this.evars = (fs.statSync(this.envfile)) && require(this.envfile)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use fs.statSync because if the env.json file does not exist most apps probably wont work to the error (with full stack trace) is appropriate. what do you think?

this.id = process.env['ENV_ID']
}

Expand Down Expand Up @@ -102,4 +103,4 @@ Env.prototype.del = function (name) {

function createEnv (envfile) {
return new Env(envfile)
}
}
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "env"
, "version": "0.0.2"
, "version": "1.0.0"
, "description": "Environment variable manager"
, "keywords": ["process", "environment", "env"]
, "author": "Daniel D. Shaw <dshaw@dshaw.com> (http://dshaw.com)"
Expand All @@ -17,10 +17,21 @@
, "test" : "test"
}
, "devDependencies": {
"tap": "0.0.x"
"codeclimate-test-reporter": "0.1.0"
, "istanbul": "^0.3.17"
, "pre-commit": "1.0.10"
, "tape": "^4.0.0"
}
, "scripts" : {
"test" : "tap ./test/*.js"
"test" : "tape ./test/*.js"
, "coverage" : "istanbul cover tape ./test/env.test.js"
, "check-coverage" : "istanbul cover tape ./test/*.js && istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100"
, "codeclimate": "CODECLIMATE_REPO_TOKEN=5eff89a1f915b11bf7665cf239a7cb9d972d93e8bd2604f67429ba946b5f06ee ./node_modules/codeclimate-test-reporter/bin/codeclimate.js < ./coverage/lcov.info"
}
, "engines": { "node": ">= 0.5.9" }
, "pre-commit": [
"check-coverage",
"codeclimate"
]
, "engines": { "node": ">= 0.10.0" }
, "keywords": [ "env", "environment", "variables", "config" ]
}
14 changes: 7 additions & 7 deletions test/env.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var Env = require('..')
, env = require('..')('./fixtures/env.json')
, tap = require('tap')
, test = tap.test
, Path = require('path')
, env_json = Path.resolve(__dirname + '/fixtures/env.json')
, env = require('..')(env_json)
, test = require('tape')

test('env core', function (t) {
t.ok(Env.version)
Expand All @@ -10,7 +11,7 @@ test('env core', function (t) {
t.ok(env.set)
t.ok(env.del)

t.equal(env.evars, require('./fixtures/env.json'))
t.equal(env.evars, require(env_json))

t.end()
})
Expand Down Expand Up @@ -76,7 +77,7 @@ test('env get all', function (t) {

test('env id', function (t) {
env.set('ENV_ID', '1')
var env2 = require('..')('./fixtures/env.json')
var env2 = require('..')(env_json)
t.equal(env2.id, '1')

t.end()
Expand All @@ -85,9 +86,8 @@ test('env id', function (t) {
test('env with no env.json', function (t) {
var env3 = require('..')()
t.ok(env3.evars)
t.isa(env3.evars, 'object')
t.ok(typeof env3.evars === 'object', 'env is an object');
t.deepEqual(env3.evars, {})
t.deepEqual(env3.get(), {})

t.end()
})