-->

Node.js, express.js, Windows Server and EADDRINUSE

2019-09-10 15:28发布

问题:

I've got a node.js express.js server setup. It's really simple, just serves up a static html page and listens on port 17500:

const path = require('path');
const express = require('express');
const app = express();
const port = 17500;

const index = path.join(__dirname, 'index.html');

console.log('Current NodeJs Version:', process.version);
console.log('Index.html:', index);

app.use((req, res) => res.sendFile(index));

app.listen(port, function (err) {
  if (err){
    console.error(err.message);
    process.exit();
  }else{
    console.log('Listening on port', port);
  }
});

It was working fine until it was force closed. Now whenever I try and run it it says Error: listen EADDRINUSE :::17500. Node is not running and netstat -an does not show any connections on 17500. Stranger still, if I change the port to one I know is not in use (21000, e.g.) it says Error: listen EADDRINUSE :::21000.

Anyone have any idea what is wrong? Bear in mind, I must not restart the server!