NodeJS Exit on Keypress
Introduction
This is an example of how easy it is to exit a NodeJS application by pressing a key. This code also will terminate the NodeJS application if the system sends it a "SIGTERM" command.
Example Code
/*
* Exit handler
*/
function exit() {
console.log('\n--App Exit--');
process.exit();
}
process.on('SIGTERM', exit );/*
* Handle Keypress
*/
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', exit );
0 comments :
Post a Comment