Skip to content

Instantly share code, notes, and snippets.

@marocchino
Forked from ppcano/app.js
Created November 19, 2011 10:55
Show Gist options
  • Save marocchino/1378715 to your computer and use it in GitHub Desktop.
Save marocchino/1378715 to your computer and use it in GitHub Desktop.
Express Boostrapping
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