Skip to content

Instantly share code, notes, and snippets.

@tsq
Created May 18, 2015 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsq/ce95153e2a1015d80d37 to your computer and use it in GitHub Desktop.
Save tsq/ce95153e2a1015d80d37 to your computer and use it in GitHub Desktop.
whether a module or a server
/**
*
* Created by tommytang on 5/18/15.
*/
var express = require("express");
var http = require("http");
var app = express();
var server = http.createServer(app);
app.set('port', 3000);
var boot = function () {
server.listen(app.get('port'), function () {
console.log('listening on port ' + app.get('port'));
});
};
var shutdown = function () {
server.close();
};
console.log("require\n", require.main);
if (require.main === module) {
boot();
} else {
console.log('running as a module');
exports.boot = boot;
exports.shutdown = shutdown;
exports.port = app.get('port');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment