It's better to separate 'development' and 'production' configs.
I use following way: Here is my config/index.js file:
const config = {
dev : {
ip_address : '0.0.0.0',
port : 8080,
mongo :{
url : "mongodb://localhost:27017/story_box_dev",
options : ""
}
},
prod : {
ip_address : '0.0.0.0',
port : 3000,
mongo :{
url : "mongodb://localhost:27017/story_box_prod",
options : ""
}
}
}
For require the config use following:
const config = require('../config')[process.env.NODE_ENV];
Than you can use your config object:
const ip_address = config.ip_address;
const port = config.port;