Skip to content

Commit 1005077

Browse files
committed
setting up .env environment
1 parent 96c805d commit 1005077

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.env

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
APP_NAME=Express
2+
APP_ENV=local
3+
APP_DEBUG=true
4+
APP_LOG_LEVEL=debug
5+
6+
DB_CONNECTION=mongodb
7+
DB_HOST=localhost
8+
DB_PORT=27017
9+
DB_DATABASE=emmra
10+
11+
MEMCACHED_HOST=localhost
12+
MEMCACHED_PORT=11211

bin/www

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ global.memcachedMiddleware = (duration) => {
2727
}
2828
};
2929

30+
/**
31+
* Load .env file.
32+
*/
33+
34+
require('dotenv').config();
35+
3036
/**
3137
* Module dependencies.
3238
*/
@@ -43,11 +49,11 @@ var mongoose = require('mongoose');
4349
var Memcached = require('memcached');
4450

4551
/**
46-
* Variable for connecting to memcached and mongodb
52+
* Variable for connecting to memcached and mongodb.
4753
*/
4854

49-
var dbURI = 'mongodb://localhost:27017/emmra',
50-
memcachedURI = 'localhost:11211';
55+
var dbURI = `${process.env.DB_CONNECTION}://${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_DATABASE}`,
56+
memcachedURI = `${process.env.MEMCACHED_HOST}:${process.env.MEMCACHED_PORT}`;
5157

5258
/**
5359
* Get port from environment and store in Express.
@@ -63,7 +69,7 @@ app.set('port', port);
6369
var server = http.createServer(app);
6470

6571
/**
66-
* Connect to mongodb using mongoose npm module
72+
* Connect to mongodb using mongoose npm module.
6773
*/
6874

6975
mongoose.connect(dbURI);

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"cookie-parser": "~1.4.3",
1010
"debug": "~2.6.9",
11+
"dotenv": "^6.0.0",
1112
"express": "~4.16.0",
1213
"http-errors": "~1.6.2",
1314
"memcached": "^2.2.2",

0 commit comments

Comments
 (0)