From 5a45ce9a6430ca7265a7d78969c3545c8fa8e90b Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Thu, 25 Feb 2021 12:13:45 +0530 Subject: [PATCH] Add basic dotenv-powered config --- .sample-env | 1 + index.js | 9 +++++++-- package.json | 1 + yarn.lock | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .sample-env diff --git a/.sample-env b/.sample-env new file mode 100644 index 0000000..d953e37 --- /dev/null +++ b/.sample-env @@ -0,0 +1 @@ +SNIPBOT_PORT=5000 diff --git a/index.js b/index.js index 681e8c4..2ec21b7 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,17 @@ const express = require("express") const bodyParser = require("body-parser") +// Let's load some configuration! +require("dotenv").config() + +const port = process.env.SNIPBOT_PORT || 5000 + const app = express() app.use(bodyParser.json()) -app.listen(5000, () => { - console.log(`Server is running on port 5000.`) +app.listen(port, () => { + console.log(`Server is running on port ${port}.`) }) app.get("/", (req, res) => { diff --git a/package.json b/package.json index 6487d46..94b2f6e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "private": true, "dependencies": { "body-parser": "^1.19.0", + "dotenv": "^8.2.0", "express": "^4.17.1" } } diff --git a/yarn.lock b/yarn.lock index e241d85..1876bfa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -75,6 +75,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"