What is the Windows equivalent of process.on('SIGINT') in node.js?
node.js, windows
Solution
You have to use the readline module and listen for a SIGINT event:
http://nodejs.org/api/readline.html#readline_event_sigint
if (process.platform === "win32") {
var rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("SIGINT", function () {
process.emit("SIGINT");
});
}
process.on("SIGINT", function () {
//graceful shutdown
process.exit();
});
Problem
I'm following the guidance here (listening for `SIGINT` events) to gracefully shutdown my Windows-8-hosted node.js application in response to Ctrl+C or server shutdown. But Windows doesn't have `SIGINT`. I also tried `process.on('exit')`, but that seems to late to do anything productive. On Windows, this code gives me: Error: No such module ``` process.on( 'SIGINT', function() { console.log( "\ngracefully shutting down from SIGINT (Crtl-C)" ) // wish this worked on Windows process.exit( ) }) ``` On Windows, this code runs, but is too late to do anything graceful: ``` process.on( 'exit', function() { console.log( "never see this log message" ) }) ``` Is there a `SIGINT` equivalent event on Windows?