Skip to content

Instantly share code, notes, and snippets.

@terrancesnyder
Created September 7, 2012 21:14
Show Gist options
  • Save terrancesnyder/3669704 to your computer and use it in GitHub Desktop.
Save terrancesnyder/3669704 to your computer and use it in GitHub Desktop.
Handling Ctrl-C cleanly in Node.js
// Show how to handle Ctrl+C in Node.js
var zmq = require('zmq')
, socket = zmq.createSocket('rep');
socket.on('message', function(buf) {
// echo request back
socket.send(buf);
});
process.on('SIGINT', function() {
socket.close();
process.exit();
});
socket.bindSync('tcp://*:5555');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment