From 3015eeb2626c77df780eeae73b7b32049c8e209b Mon Sep 17 00:00:00 2001 From: Jennifer Nguyen Date: Wed, 1 Jul 2020 23:56:18 -0700 Subject: [PATCH] Adding dependency to load variables from .env file --- package-lock.json | 5 +++++ package.json | 1 + src/config.ts | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d457db1..5afbfd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -491,6 +491,11 @@ "is-obj": "^2.0.0" } }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", diff --git a/package.json b/package.json index 63ff166..a3aed5e 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "main": "index.js", "license": "MIT", "dependencies": { + "dotenv": "^8.2.0", "express": "^4.17.1", "pg": "^8.2.1" }, diff --git a/src/config.ts b/src/config.ts index d9516d7..c6344bc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,8 @@ +require('dotenv').config() + if (!process.env.PORT) { - console.log("Missing environment variable PORT"); - process.exit(1); + console.log("Missing environment variable PORT"); + process.exit(1); } export const port: number = parseInt(process.env.PORT as string, 10);