Created
January 29, 2021 18:36
-
-
Save tsturzl/029d3863a3c2cdbc214a174d72c6ddb6 to your computer and use it in GitHub Desktop.
simple nodejs config example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config=require('./config.json')[process.env.NODE_ENV || 'production']; | |
console.log(config.db.hosts) | |
console.log(config.redis.hosts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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