Reputation: 101
I am the old Java developer moved to Node.js world recently and trying to find a decent way to manage configurations for node.js applications.
I've done some search and seeing that people stored configs directly in src repository (e.g. in config.js file with the help of other 3-rd party modules). However, i think with this approach, every time we want to make change of configs, we need to commit something to the repository and redeploy the application, right?
Is there any ways in the Nodejs application where we can config (e.g. database connections) from outside of application scope, like in Java we have JNDI or server context.xml file?
Upvotes: 0
Views: 647
Reputation: 7237
You can use environment variables process.env.MYVAR
.
Usually, i have a config file like this
'use strict'
module.exports = (function() {
return {
port: process.env.PORT || 3000,
passwordSalt: process.env.PASSWORD_SALT,
tokenSecret: process.env.TOKEN_SECRET,
}
})()
Upvotes: 1