aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.env.example1
-rw-r--r--.gitignore1
-rw-r--r--README.md2
-rw-r--r--index.js4
-rw-r--r--package-lock.json5
-rw-r--r--package.json1
6 files changed, 13 insertions, 1 deletions
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"