Skip to content

Instantly share code, notes, and snippets.

@tsturzl
Created January 29, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsturzl/029d3863a3c2cdbc214a174d72c6ddb6 to your computer and use it in GitHub Desktop.
Save tsturzl/029d3863a3c2cdbc214a174d72c6ddb6 to your computer and use it in GitHub Desktop.
simple nodejs config example
var config=require('./config.json')[process.env.NODE_ENV || 'production'];
console.log(config.db.hosts)
console.log(config.redis.hosts)
module.exports = {
"dev": {
"db": {
"hosts":["localhost"],
"database": "api"
},
"redis": {
"hosts": ["localhost"]
}
},
"staging": {
"db": {
"hosts":["1.1.1.1"],
"database": "api"
},
"redis": {
"hosts": ["2.2.2.2"]
}
},
"production": {
"db": {
// Gets comma seperated hosts from environment, otherwise default to 1.1.1.1
"hosts": (proccess.env.DB_HOSTS.split(",") || "1.1.1.1"),
"database": "api"
},
"redis": {
// Get redis hosts from env, otherwise default to 2.2.2.2 and 2.2.2.3
"hosts": (proccess.env.DB_HOSTS.split(",") || "2.2.2.2,2.2.2.3")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment