-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (23 loc) · 682 Bytes
/
index.js
File metadata and controls
28 lines (23 loc) · 682 Bytes
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
const { readFileSync } = require("fs");
const { parse } = require("yaml");
const { env } = process;
const config = () => {
const configs = readFileSync(`${process.cwd()}/.env`, {
encoding: "utf8",
});
if(!configs) throw new Error("No .env file found");
const parsed = parse(configs);
const isProd = parsed?.isProduction;
const isProduction = Boolean(isProd);
console.log("isProduction", isProduction);
console.log("parsed", parsed);
const myConfig = isProduction ? parsed?.production : parsed?.dev;
const keys = Object.keys(myConfig);
for (const key of keys) {
env[key] = myConfig[key];
}
return myConfig;
};
module.exports = {
config,
};