Created
September 13, 2011 18:25
-
-
Save ppcano/1214585 to your computer and use it in GitHub Desktop.
Express Boostrapping
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
var express = require('express') | |
, path = require('path'); | |
process.on('uncaughtException', function (err) { | |
console.log('uncaught exception:--------------------------------------------- ' ); | |
console.log( err + err.stack); | |
}); | |
mainServer = module.exports = express.createServer(); | |
mainServer.set('path', __dirname); | |
exports.boot = function (app, next) { | |
var lib_path = path.join(app.settings.path, 'lib'); | |
require( path.join(lib_path, 'settings') ).bootConfiguration(app) | |
.bootErrorConfig(app); | |
require( path.join(lib_path, 'models') ).bootModels(app, function (err) { | |
if (!err) { | |
require( path.join(lib_path, 'controllers') ).bootControllers(app, function(err){ | |
if (!err) { | |
next(); | |
} else { | |
console.log('Exception either loading controllers files' ); | |
} | |
}); | |
} else { | |
console.log('Exception either loading model files or mongo connection' ); | |
} | |
}); | |
} | |
if (!module.parent) { | |
exports.boot(mainServer, function( ) { | |
mainServer.listen(process.env.PORT || 3000); | |
console.log("Express server listening on port %d in %s mode", mainServer.address().port, mainServer.settings.env); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment