Skip to content

Instantly share code, notes, and snippets.

@godfreyd godfreyd/index.js
Created May 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.