Skip to content

Instantly share code, notes, and snippets.

@joshkehn
Created November 17, 2011 18:31
Show Gist options
  • Save joshkehn/1374017 to your computer and use it in GitHub Desktop.
Save joshkehn/1374017 to your computer and use it in GitHub Desktop.
var http = require('http');
function catch_sigint (server) {
process.on('SIGINT', function () {
process.stdout.write('\r');
console.log('Interrupt');
try {
server.close();
} catch (e) {
process.exit();
}
});
}
var server = http.createServer();
catch_sigint(server);
server.on('close', function (err) {
if (err) {
console.error(err);
}
console.log('Server closed.');
});
server.on('request', function (req, res) {
console.log('Got request.');
res.end('Hello');
});
server.listen(2001);
console.log('Server listening at http://localhost:2001/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment