Reputation: 13
i am new to nodejs. I want to set up database(mongoose) configuration for production in a separate file same as we use properties file in java. Please help me with some example.
Upvotes: 1
Views: 1335
Reputation: 176
I recommend using node-config
as best practice, you will have to create a config
folder with config files corresponding to your NODE_ENV
for example, if you have three env:
development
: local development hostproduction
: production hoststaging
: staging hostyou'll have to create 3 files plus a default.js
config file, node-config
will override default settings with the config file corresponding to NODE_ENV
module.exports = {
// node port
port: 3000
// other default settings
};
module.exports = {
// mongo url
mongoUrl: "mongodb://localhost/db"
};
module.exports = {
// mongo url
mongoUrl: "mongodb://production.mongo.host/db"
};
module.exports = {
// mongo url
mongoUrl: "mongodb://staging.mongo.host/db"
};
Upvotes: 1