Put index.js
to settings
folder of your app, use like var settings = require('./settings')
. Add as many environment specific files (development.js, testing.js, staging.js, production.js, etc) as you need. Use them from one another as you wish. Use local.js to override any option on given machine. Don't forget to include settings/local.js
to .gitignore!
Created
November 4, 2014 05:18
-
-
Save hogart/a18368eba492e70396cd to your computer and use it in GitHub Desktop.
django-like settings for node projects
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
'use strict'; | |
var env = process.env.NODE_ENV || 'development'; // development by default | |
var config = {}; | |
try { | |
config = require('./local'); // local.js has priority | |
} catch (e) { | |
config = require('./' + env); // if local.js is not present, get config with environment name | |
} | |
module.exports = config; |
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
'use strict'; | |
// put this file in .gitignore, it is machine specific | |
var conf = require('./testing'); // inherit config from another | |
//override some settings | |
conf.godCredentials = { // simpler credentials for developer needs | |
name: 'admin', | |
pass: 'Qwerty123' | |
} | |
conf.port = 1337; // I ran app locally on any port I choose | |
conf.db = 'http://testing.application.com:16737'; // but I use testing db for now | |
module.exports = conf; |
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
'use strict'; | |
module.exports = { | |
// gettings settings from environment variables are useful when running under Dokku or similar deployment system | |
db: process.env.MONGO_URL, // mongo connection string | |
port: process.env.PORT, // port to run app on | |
godCredentials: { // credentials for back-office | |
name: '15045784', | |
pass: 'nUgjVnycrhuWyQPNuYlCnbJ4u' | |
}, | |
// some API keys or whatever | |
twitterKey: '', | |
twiterSecret: '' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment