Skip to content

Commit

Permalink
feat(config): ✨ added \node-config\
Browse files Browse the repository at this point in the history
  • Loading branch information
MauroJr committed Nov 11, 2018
1 parent 943fdfb commit aad9483
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
HELLO=HELLO
HELLO=WORLD
3 changes: 3 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "HELLO"
}
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"hello": "hello from config",
"hi": "hi from config"
}
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"node": ">=8.3.0",
"npm": ">=5.2.0"
},
"dependencies": {},
"dependencies": {
"config": "^2.0.1"
},
"keywords": [
"modern",
"node",
Expand All @@ -30,7 +32,7 @@
"?start:prod": "Startup the module with a `production` environment.",
"start:prod": "NODE_ENV=production node -r dotenv/config ./lib/index.js",
"?start:dev": "Startup the module with a `development` environment.",
"start:dev": "node node -r dotenv/config ./src/index.js",
"start:dev": "NODE_ENV=development node -r dotenv/config ./src/index.js",
"?debug": "Start a debugger for the `main` entry point.",
"debug": "node --inspect --debug-brk -r dotenv/config ./src/index.js",
"?debug:tests": "Start a debugger for the tests",
Expand Down
19 changes: 17 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
'use strict';

exports.hello = function hello() {
return process.env.HELLO;
const config = require('config');


exports.fromEnv = {
HELLO() {
return process.env.HELLO;
}
};

exports.fromConfig = {
hi() {
return config.get('hi');
},

hello() {
return config.get('hello');
}
};
17 changes: 11 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict';

const { expect } = require('chai');
const { hello } = require('../src');
const { fromConfig, fromEnv } = require('../src');

describe('Importing The index module', function () {
it('should be a function', function () {
expect(hello).to.be.a('function');

describe('Checking Environment Variable `HELLO`', function () {
it('should return value from environment variable', function () {
expect(fromEnv.HELLO()).to.be.equal('WORLD');
});

it('should return value from config file', function () {
expect(fromConfig.hi()).to.be.equal('hi from config');
});

it('should return `HELLO` string from env', function () {
expect(hello()).to.be.equal('HELLO');
it('should return value from custom environment variable', function () {
expect(fromConfig.hello()).to.be.equal('WORLD');
});
});

0 comments on commit aad9483

Please sign in to comment.