Last active
August 29, 2015 14:15
-
-
Save jrgcubano/e30d36c2306c91de17f5 to your computer and use it in GitHub Desktop.
Running Express.js in Production Mode
This file contains hidden or 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
// First export vars | |
echo export NODE_ENV=production >> ~/.bash_profile | |
$ source ~/.bash_profile | |
// then start the serverin some mode (production default) | |
NODE_ENV=testing node app.js | |
Load the environment config in ./config/index.js | |
var env = process.env.NODE_ENV || 'development' | |
, cfg = require('./config.'+env); | |
module.exports = cfg; | |
Define some defaults in ./config/config.global.js | |
var config = module.exports = {}; | |
config.env = 'development'; | |
config.hostname = 'dev.example.com'; | |
//mongo database | |
config.mongo = {}; | |
config.mongo.uri = process.env.MONGO_URI || 'localhost'; | |
config.mongo.db = 'example_dev'; | |
Override the defaults in ./config/config.test.js | |
var config = require('./config.global'); | |
config.env = 'test'; | |
config.hostname = 'test.example'; | |
config.mongo.db = 'example_test'; | |
module.exports = config; | |
Using it in ./models/user.js: | |
var mongoose = require('mongoose') | |
, cfg = require('../config') | |
, db = mongoose.createConnection(cfg.mongo.uri, cfg.mongo.db); | |
Running your app in test environment: | |
NODE_ENV=test node ./app.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment