'Can't stop local node server with Ctrl + C (Mac)

I have never had this problem when developing node server locally. It may have started after updating xCode.

I tried with the simplest code

var app = express();
var server = app.listen(process.env.PORT || '3000', '0.0.0.0', function() {
    console.log('App listening at http://%s:%s', server.address().address, server.address().port);
});

process.on('SIGINT', function() {
 console.log("Exiting...");
 process.exit();
});

but can't observe any log when I try Ctr+C to quit.

UPDATE When I tried pressing and holding 3-4 seconds it worked ..weird because pressing 10-20 times without holding didn't work

App listening at http://0.0.0.0:3000
cccccccccccccccccccccccccccccccccccccccccccccc^CExiting...


Solution 1:[1]

Because you're using OSX, type Ctrl+C instead of Cmd+C.

Solution 2:[2]

In addition to Pat Needham's answer, Also check Apple Logo > System Preferences > Keyboard > Shortcuts. If you enable any unchecked item and enter ctrl+c, then it will show which one has also ctrl+c.

Solution 3:[3]

For me it was because I had this line in my code:

process.stdin.setRawMode(true);

I had this in my code so I could read global hotkeys, but forgot I left it there. Removing it or setting raw mode to false allowed nodejs to properly catch sigint again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pat Needham
Solution 2 Brian Hong
Solution 3 Dharman