Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:00+00:00 2026-05-29T09:20:00+00:00

I am working on a node project where I want to write some memory

  • 0

I am working on a node project where I want to write some memory to a file when exiting. I figured it was as simple as:

process.on('exit', function () {
 //handle your on exit code
 console.log("Exiting, have a nice day");
});

However, this code does not execute (on Windows) when CTRL+C is received. Given this is the defacto way to exit Node, this seems a bit of a problem.

At this point I tried to handle the signal ( on.('SIGINT',...) ) instead, which results in the error:

node.js:218 
        throw e; // process.nextTick error, or 'error' event on first tick 
              ^  Error: No such module 
    at EventEmitter.<anonymous> (node.js:403:27) 
    at Object.<anonymous> (C:\Users\Mike\workspace\NodeDev\src\server.js:5:9) 
    at Module._compile (module.js:434:26) 
    at Object..js (module.js:452:10) 
    at Module.load (module.js:353:32) 
    at Function._load (module.js:310:12) 
    at Array.0 (module.js:472:10) 
    at EventEmitter._tickCallback (node.js:209:41)

Off to a quick Google and it appears Node simply doesn’t handle signals on Windows and CTRL+C does not in fact trigger the "exit" event. The above error should not exit on a *Nix system.

However, switching off the Windows platform is not a valid option for me, so I need a workaround. Is there a way to handle On Exit events in Node that are caused by the user pressing CTRL+C to terminate the script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:20:00+00:00Added an answer on May 29, 2026 at 9:20 am

    I used this piece of code for listening for keys. It seems to work for CTRL + C as well on Windows.

    But then again it only works for CTRL + C as a key combination, not anything else. Of course, you could both bind a function to process.on("exit", and call it inside the if block below.

    var tty = require("tty");
    
    process.openStdin().on("keypress", function(chunk, key) {
      if(key && key.name === "c" && key.ctrl) {
        console.log("bye bye");
        process.exit();
      }
    });
    
    tty.setRawMode(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project where I have some hierarchical data that I want
I'm working on a simple node.js project that requires authentication. I decided to use
I'm working on a project built entirely in node.js and coffeescript. I want to
I am working on some code were I need to add a Node into
I'm working on a simple carousel. My problem appears when trying to insert node
I'm working on a project that includes WebSockets, and data between the server (Node.js)
I'm using ksoap2-Android on an Android project to upload a file. It's not working.
In a Ruby project I'm working with a badly formed xml file that comes
I am working on an application in Node.js and because this project is for
I'm still working on my zoomable node-graph project. I'm currently having problems with what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.