diff --git a/.env b/.env index 5bb6eb7..d77e8f1 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -HELLO=HELLO +HELLO=WORLD diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json new file mode 100644 index 0000000..a1196fc --- /dev/null +++ b/config/custom-environment-variables.json @@ -0,0 +1,3 @@ +{ + "hello": "HELLO" +} \ No newline at end of file diff --git a/config/default.json b/config/default.json new file mode 100644 index 0000000..461844d --- /dev/null +++ b/config/default.json @@ -0,0 +1,4 @@ +{ + "hello": "hello from config", + "hi": "hi from config" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0154d26..47f3c26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2129,6 +2129,24 @@ "typedarray": "^0.0.6" } }, + "config": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/config/-/config-2.0.1.tgz", + "integrity": "sha512-aTaviJnC8ZjQYx8kQf4u6tWqIxWolyQQ3LqXgnCLAsIb78JrUshHG0YuzIarzTaVVe1Pazms3TXImfYra8UsyQ==", + "requires": { + "json5": "^1.0.1" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "http://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "requires": { + "minimist": "^1.2.0" + } + } + } + }, "configstore": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/configstore/-/configstore-3.1.2.tgz", @@ -5540,8 +5558,7 @@ "minimist": { "version": "1.2.0", "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "minimist-options": { "version": "3.0.2", diff --git a/package.json b/package.json index 2991543..244adab 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "node": ">=8.3.0", "npm": ">=5.2.0" }, - "dependencies": {}, + "dependencies": { + "config": "^2.0.1" + }, "keywords": [ "modern", "node", @@ -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", diff --git a/src/index.js b/src/index.js index 4a6ac37..61e1d01 100644 --- a/src/index.js +++ b/src/index.js @@ -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'); + } }; diff --git a/test/index.test.js b/test/index.test.js index dd9bfca..e6bede6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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'); }); });