Description
- Version: v6.11.3
- Platform: 64-bit Windows 10
- CLI: Git 2.14.1
- Express Version: 4.16.1
Referencing #4182 which seems similar (but at the end, it was stated that a new issue should be opened).
Ctrl + C does not kill the server. The resolution to the issue was using:
process.on('SIGINT', function() {
process.exit();
});
however, when I use it, my server exits immediately. It completely skips app.listen()
and exits completely, even when I previously kill the process on the specific port. Without the process.exit()
function, it starts up and I can Ctrl + C
to exit, but the process still runs in the background. I opened an issue on StackOverflow which hasn't gone anywhere really. This happens across multiple projects, so it's not just one project. I'm pretty sure it started happening when I updated node.
I am able to use netstat -aon
to list it, then tskill <pid>
to kill it afterwards, but this isn't really a solution.
Here's my code with my express server:
const express = require('express');
const app = express();
var config = require('./config')(process.env.NODE_ENV);
var appPort = process.env.PORT || config.port;
app.listen(appPort, function () {
console.log('UAction Test Server Running on Port ' + appPort + '!');
});
process.on('SIGINT', function() {
console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit(1);
});
UPDATE
So the server is able to start now with:
process.on('SIGINT', function() {
console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit(1);
});
I added app.use('/', express.static('./src'));
, but removing it didn't change anything.
When I do Ctrl + C
, the console.log("\nGracefully shutting down from SIGINT (Ctrl-C)" );
doesn't appear, and trying to restart causes the same issue. Just for reference, here's the log:
$ npm start
> express-test@1.0.0 start E:\github\uaction\express-test
> node index.js
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::1337
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1258:14)
at listen (net.js:1294:10)
at Server.listen (net.js:1390:5)
at EventEmitter.listen (E:\github\uaction\express-test\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\github\uaction\express-test\index.js:9:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! express-test@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express-test@1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the express-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs express-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls express-test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! E:\github\uaction\express-test\npm-debug.log