-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurator.js
40 lines (33 loc) · 1007 Bytes
/
configurator.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
35
36
37
38
39
40
const fs = require('fs');
function config() {
if (!process.env.NODE_ENV)
process.env.NODE_ENV = 'development';
else
process.env.NODE_ENV = process.env.NODE_ENV.toLowerCase();
console.log(`Node Mode: ${process.env.NODE_ENV}`);
const dotenvPath = `./config/${process.env.NODE_ENV}.env`;
if (checkFileExists(dotenvPath)) {
console.log('Configure from ' + dotenvPath);
const dotenvResult = require('dotenv').config({ path: dotenvPath });
if (dotenvResult.error) {
console.log('Dotenv error :');
console.log(dotenvResult.error);
}
}
else
console.log('Use Environment Variables');
return {
host: process.env.host,
port: Number(process.env.port),
dburl: process.env.dburl
};
}
function checkFileExists(p) {
try {
fs.accessSync(p);
return fs.lstatSync(p).isFile();
} catch (error) {
return false;
}
}
module.exports.config = config;