Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@godfreyd
Created May 24, 2017 09:24
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 godfreyd/37d903c73f863619e2e1be1cd946d4c3 to your computer and use it in GitHub Desktop.
Save godfreyd/37d903c73f863619e2e1be1cd946d4c3 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
app = require('./app'),
config = require('./config'),
env = process.env,
port = env.PORT || (env.PORT = config.defaultPort),
isSocket = isNaN(port);
exports.start = function() {
app
.listen(port, () => {
isSocket && fs.chmod(port, '0777');
console.log('server is listening on', port);
})
.once('error', (err) => {
console.log('worker %s has failed to start application', process.pid);
if (err.code === 'EADDRINUSE') {
console.log('port or socket %s is taken', port);
process.kill();
return;
}
console.log(err.stack);
});
};
if (!module.parent) {
if (fs.existsSync(port)) {
try {
fs.unlinkSync(port);
} catch (e) {}
}
exports.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment