move dotenv config from server index to the config file

This commit is contained in:
Bilal Catic
2020-02-18 11:05:47 +01:00
parent 742f1baba4
commit 020102cb27
2 changed files with 14 additions and 4 deletions

View File

@@ -1,3 +1,17 @@
import dotenv from "dotenv";
import fs from "fs";
dotenv.config();
if (process.env.NODE_ENV === "test"){
try{
const envConfig = dotenv.parse(fs.readFileSync('.test.env'));
for (const k of Object.keys(envConfig)) {
process.env[k] = envConfig[k];
}
}catch (e) {
//Use .env file values
}
}
const SERVER_PORT:number = parseInt(process.env.SERVER_PORT, 10) || 8080;
const VALID_EXPORT_TYPES: {[key:string]: string} = {

View File

@@ -1,11 +1,7 @@
import express from "express";
import dotenv from "dotenv";
import * as bodyParser from 'body-parser';
import * as routes from "./routes"
dotenv.config();
const app = express();
app.use(bodyParser.json());