What is the Windows equivalent of process.on('SIGINT') in node.js?

前端 未结 6 1339
北海茫月
北海茫月 2020-11-28 02:47

I\'m following the guidance here (listening for SIGINT events) to gracefully shutdown my Windows-8-hosted node.js application in response to Ctrl+

6条回答
  •  感动是毒
    2020-11-28 03:50

    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();
    });
    

提交回复
热议问题