Created
May 27, 2020 05:29
-
-
Save msssk/d336f9bfec996f15815180e873f02b99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (process.platform === 'win32') { | |
var readline = require('readline'); | |
var readlineInterface = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
readlineInterface.on('SIGINT', function () { | |
process.emit('SIGINT'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have an event handler for "Ctrl+C" that only uses
process.on('SIGINT')
to gracefully terminate your Node.js process it does not quite work on Windows. As a Windows user I am quite accustomed to using development tools written in Node.js that I have to go through an additional step of confirming that I want to terminate the batch job:If you include the code in this gist then Node.js processes on Windows will gracefully terminate from "Ctrl+C" with no additional confirmation prompt.