Skip to content

Commit

Permalink
feat: add env variable CONFIG which will be used to load the configur…
Browse files Browse the repository at this point in the history
…ation file. If not set, the NODE_ENV will be used to load configuration
  • Loading branch information
Andreas Krummsdorf committed Mar 19, 2015
1 parent a29a9a6 commit a7970a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Start the application without Live reload. The configuration of the command can
Start the application manually without live reload. Note here the environment variables.
This command is run in the background when npm start

$ DEBUG=* PORT=3000 HOST=localhost NODE_ENV=development node baboon-backend.js
$ DEBUG=* PORT=3000 HOST=localhost NODE_ENV=development CONFIG=test node baboon-backend.js

### Debug
We debug the application frequently about our WebStorm IDE. But you can also debug your app with nodemon and node-inspector.
Expand Down
6 changes: 4 additions & 2 deletions lib/LxConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var _ = require('lodash');
* @returns {{}}
*/
module.exports = function (rootPath) {

var self = {};
var debug = require('debug')('baboon:LxConfig');
var pkg = require(path.join(rootPath, 'package.json'));
Expand All @@ -29,9 +28,12 @@ module.exports = function (rootPath) {
self.NODE_ENV = process.env.NODE_ENV;
self.PORT = process.env.PORT;
self.HOST = process.env.HOST;
self.CONFIG_NAME = process.env.CONFIG;

var baseConfig = require(path.join(self.CONFIG_PATH, 'base.json'));
var config = _.merge(baseConfig, require(path.join(self.CONFIG_PATH, self.NODE_ENV + '.json')) || {});
debug('Configuration load:', self.CONFIG_NAME || self.NODE_ENV);

var config = _.merge(baseConfig, require(path.join(self.CONFIG_PATH, self.CONFIG_NAME || self.NODE_ENV + '.json')) || {});
self = _.merge(config, self);

debug('Configuration loaded:', self);
Expand Down

0 comments on commit a7970a1

Please sign in to comment.