aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-06-02 22:53:32 +0200
committerMateja <mail@matejamaric.com>2021-06-02 22:53:32 +0200
commitb152602c92ca6ee361f478ecf2da34a9446e4f97 (patch)
treed968b6dfad61230026ae3dde1e98e0a1b4f1a126
parent04cb777936edffb5f16c2a4515cfa2ce88256dd7 (diff)
downloadnode-playground-b152602c92ca6ee361f478ecf2da34a9446e4f97.tar.gz
node-playground-b152602c92ca6ee361f478ecf2da34a9446e4f97.zip
Add `env.js`.
-rw-r--r--config/env.js6
-rw-r--r--index.js10
2 files changed, 11 insertions, 5 deletions
diff --git a/config/env.js b/config/env.js
new file mode 100644
index 0000000..6d69000
--- /dev/null
+++ b/config/env.js
@@ -0,0 +1,6 @@
+require('dotenv').config();
+module.exports = {
+ port: process.env.PORT || 8080,
+ mongoUrl: process.env.DB_CONN || "mongodb://localhost/playground_db",
+ masterKey: process.env.APP_SECRET || "you-should-use-something-different"
+};
diff --git a/index.js b/index.js
index 675233e..2d2fdef 100644
--- a/index.js
+++ b/index.js
@@ -5,7 +5,7 @@ const session = require('express-session');
const MongoSessionStore = require('connect-mongo');
const flash = require('connect-flash');
const passport = require('passport');
-require('dotenv').config();
+const {port, mongoUrl, masterKey} = require("./config/env")
const oldForm = require('./utils/middleware/oldForm');
@@ -13,18 +13,18 @@ const webRoutes = require('./routes/web');
const app = express();
-mongoose.connect(process.env.DB_CONN, {
+mongoose.connect(mongoUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
});
app.use(session({
- secret: process.env.APP_SECRET,
+ secret: masterKey,
resave: false,
saveUninitialized: true,
store: MongoSessionStore.create({
- mongoUrl: process.env.DB_CONN
+ mongoUrl: mongoUrl
}),
cookie: {
maxAge: 1000 * 60 * 60 * 24 // 1 day
@@ -48,4 +48,4 @@ app.use(oldForm);
app.use('/', webRoutes);
-app.listen(process.env.PORT || 8080, () => console.log(`Server started on port ${process.env.PORT || 8080}.`));
+app.listen(port, () => console.log(`Server started on port ${port}.`));