0

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...
user3211198
  • 223
  • 1
  • 5
  • 14
  • 1
    Surely that's not the only code you have in your script... You should post a minimal, reproducible example instead. It's quite possible you have something that is keeping the event loop too busy and node is not able to process the key press. – mscdex Jul 16 '17 at 20:56
  • If you can't stop it, then presumably something else is trapping it. Does a trivial program with a `setTimeout()` call to keep it stalled open stop properly? – tadman Jul 16 '17 at 21:21
  • I tried running only express but nothing else and still have the same problem. It was not like this a couple of days ago. Updating XCode may have introduced this – user3211198 Jul 16 '17 at 21:27
  • 1
    Xcode shouldn't affect your terminal. I think your terminal settings have changed for unrelated reasons. – tadman Jul 16 '17 at 21:58

3 Answers3

4

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

Pat Needham
  • 5,698
  • 7
  • 43
  • 63
0

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.

Brian Hong
  • 930
  • 11
  • 15
0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
DWils
  • 390
  • 1
  • 4
  • 16