Skip to content

Commit 2badee4

Browse files
committed
Add config module
1 parent e21ad4c commit 2badee4

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"App": {
3+
"database": {
4+
"url": "DATABASE_URL",
5+
"port": "DATABASE_PORT",
6+
"dbName": "DATABASE_NAME"
7+
}
8+
}
9+
}

config/database.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const mongoose = require('mongoose');
2-
const config = require('./environment');
2+
const config = require('config');
33

44
mongoose.Promise = Promise;
5+
const dbConfig = config.get('App.database');
56

6-
const mongodbUrl = config.mongodbUrl;
7+
const mongodbUrl = `${dbConfig.get('url')}:${dbConfig.get('port')}/${dbConfig.get('dbName')}`;
78

89
const connect = () => mongoose.connect(mongodbUrl, {
910
useMongoClient: true

config/default.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"App": {
3+
"database": {
4+
"url": "mongodb://mongodb",
5+
"port": 27017,
6+
"dbName": "development"
7+
}
8+
}
9+
}

config/test.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"App": {
3+
"database": {
4+
"dbName": "test"
5+
}
6+
}
7+
}

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"body-parser": "^1.18.0",
2222
"bunyan": "^1.8.12",
2323
"chai": "^4.1.2",
24+
"config": "^3.0.1",
2425
"express": "^4.15.4",
2526
"mocha": "^3.5.3",
2627
"mongoose": "^4.11.11",

0 commit comments

Comments
 (0)