From 40080d492ee22512e167bac27294683640eba281 Mon Sep 17 00:00:00 2001 From: Mateja Date: Thu, 6 May 2021 18:00:16 +0200 Subject: Started using `dotenv`. --- .env.example | 1 + .gitignore | 1 + README.md | 2 ++ index.js | 4 +++- package-lock.json | 5 +++++ package.json | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..71a28fd --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +DB_CONN=mongodb://localhost/playground_db diff --git a/.gitignore b/.gitignore index c2658d7..713d500 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +.env diff --git a/README.md b/README.md index 58d831b..2f18dc7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # About this project I use this repository to play with Node.js. + +If you want to use this repository don't forget to copy `.env.example` to `.env` and modify it accordingly. diff --git a/index.js b/index.js index b219657..28500fd 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ const express = require('express'); const exphbs = require('express-handlebars'); const mongoose = require('mongoose'); +require('dotenv').config(); + const webRoutes = require('./routes/web'); const app = express(); -mongoose.connect('mongodb://localhost/playground_db', { +mongoose.connect(process.env.DB_CONN, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false diff --git a/package-lock.json b/package-lock.json index 3dfdef5..d03875b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -417,6 +417,11 @@ "is-obj": "^2.0.0" } }, + "dotenv": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-9.0.0.tgz", + "integrity": "sha512-yy3x9XjojW8ROTBePD25AcMoHqGHsvHmtfw8QWlpEXyMMXXPj6brUA464AptUvHuTPRmNz6Sd3ZLNLeJl6dHJA==" + }, "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 b0422c5..751aead 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "Mateja Maric", "license": "GPL-3.0", "dependencies": { + "dotenv": "^9.0.0", "express": "^4.17.1", "express-handlebars": "^5.3.0", "mongoose": "^5.12.7" -- cgit v1.2.3