-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
43 lines (35 loc) · 883 Bytes
/
index.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
let environment = {}
const fs = require('fs')
const loadEnvironment = json => {
try {
let env = require(json)
Object.keys(env).forEach(function (key) {
environment[key] = env[key].toString()
process.env[key] = env[key].toString()
})
return null
} catch (e) {
return e
}
}
for (let route of ['env.json', '.env.json', '.env']) {
filepath = require('path').join(process.cwd(), route)
if (fs.existsSync(filepath)) {
let err = loadEnvironment(filepath)
if (err !== null) {
console.log('WARNING --> Configuration Problem: ' + e.message)
} else {
break
}
}
}
environment.load = (filename = null) => {
if (filename === null) {
return
}
let filepath = require('path').join(process.cwd(), filename)
if (fs.existsSync(filepath)) {
loadEnvironment(filepath)
}
}
module.exports = environment