-
-
Notifications
You must be signed in to change notification settings - Fork 852
/
main.js
44 lines (35 loc) · 1.04 KB
/
main.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
41
42
43
44
"use strict";
var fs = require('fs');
function dotenv() {
dotenv = {
environment: process.env.NODE_ENV || "development",
_loadEnv: function() {
return dotenv._setKeysAndValuesFromEnvFilePath(".env");
},
_loadEnvDotEnvironment: function() {
return dotenv._setKeysAndValuesFromEnvFilePath(".env."+dotenv.environment);
},
_setKeysAndValuesFromEnvFilePath: function(filepath) {
try {
var data = fs.readFileSync(filepath);
var content = data.toString().trim();
var lines = content.split('\n');
for (var i=0; i<lines.length; i++) {
var key_value_array = lines[i].split("=");
var key = key_value_array[0].trim();
var value = key_value_array[1].trim();
process.env[key] = value;
}
} catch (e) {
}
return true;
},
load: function() {
dotenv._loadEnvDotEnvironment();
dotenv._loadEnv();
return true;
},
};
return dotenv;
}
module.exports = dotenv;