From e15ef4f453681f3f4c52115a7e27f8740591e010 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sat, 10 Apr 2021 12:55:11 -0400 Subject: [PATCH] feat: added .env and changed tsconfig --- .gitignore | 1 + package.json | 1 + src/.env.sample | 4 ++++ src/index.ts | 17 ++++++++++------- tsconfig.json | 1 + yarn.lock | 5 +++++ 6 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/.env.sample diff --git a/.gitignore b/.gitignore index f06235c..a0d218e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist +.env \ No newline at end of file diff --git a/package.json b/package.json index a8188ee..b25406d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@types/express": "^4.17.11", "@types/node": "^14.14.37", "cors": "^2.8.5", + "dotenv": "^8.2.0", "express": "^4.17.1", "typescript": "^4.2.4" } diff --git a/src/.env.sample b/src/.env.sample new file mode 100644 index 0000000..ccf3e60 --- /dev/null +++ b/src/.env.sample @@ -0,0 +1,4 @@ +NODE_ENV='dev' +APP_PORT=3000 +DB_USER= +DB_PASS= \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 987e80d..7d55b23 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,10 @@ -import * as express from "express"; -import { users } from "./data"; -import { groups } from "./data"; +import express from "express"; +import dotenv from 'dotenv'; +import { users, groups } from "./data"; + +dotenv.config({ + path: '.env' +}); const app = express(); @@ -24,7 +28,6 @@ app.delete('/user', (req, res) => { }); - app.get("/pool", (req, res) => { }); @@ -41,7 +44,6 @@ app.delete('/pool', (req, res) => { }); - app.get("/group", (req, res) => { }); @@ -61,7 +63,6 @@ app.delete('/group', (req, res) => { }); - app.get("/join_pool", (req, res) => { }); @@ -78,4 +79,6 @@ app.delete('/join_pool', (req, res) => { }); -app.listen(80, () => void console.log("Listening on port 80")); +((port = process.env.APP_PORT || 5000) => { + app.listen(port, () => void console.log(`Listening on port ${port}`)); +})(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 2e3b371..b5da52a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "outDir": "dist/", + "esModuleInterop": true, }, "files": ["src/types.ts"], "include": ["src/"], diff --git a/yarn.lock b/yarn.lock index 9e24887..10556bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -150,6 +150,11 @@ destroy@~1.0.4: resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= +dotenv@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" + integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"