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

 ̄綄美尐妖づ 提交于 2019-12-12 03:08:59

问题


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!

来源:https://stackoverflow.com/questions/42163684/node-js-express-js-windows-server-and-eaddrinuse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!