Skip to content

Instantly share code, notes, and snippets.

@rivy
Forked from terrancesnyder/node-0mq-ctrl-c.js
Created June 25, 2022 19:25
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 rivy/5027109d81e57590cea442eff1b952fd to your computer and use it in GitHub Desktop.
Save rivy/5027109d81e57590cea442eff1b952fd 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