forked from websdotcom/BitPoints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
34 lines (28 loc) · 837 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var fs = require('fs');
/**
* Read the JSON config file for the given environment
* @param {string} env
* @returns {Object|undefined} the config object, or undefined if the config file is not found
*/
var getConfig = function(env) {
var environmentFile = 'environments/' + env + '.json';
var config;
if (fs.existsSync(environmentFile)) {
config = JSON.parse(fs.readFileSync(environmentFile));
config.env = env;
// Override port if PORT env variable is set.
if(process.env.PORT) {
config.port = parseInt(process.env.PORT);
}
return config;
} else {
return undefined;
}
};
// Attempt to get config file. If no config.json is found, use a default config.
var ENVIRONMENT = process.env.NODE_ENV || 'development';
var config = getConfig(ENVIRONMENT);
if(!config) {
process.exit(1);
}
exports.config = config;