简体   繁体   中英

NodeJS on Ubuntu 20.04 - Cannot start server because address in use (:::80) but I can't find any port listening to that address

When running the following command:

sudo node server/server.js

I receive the following error:

Listening on port 80 events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::80
    at Server.setupListenHandle [as _listen2] (net.js:1280:14)
    at listenInCluster (net.js:1328:12)
    at Server.listen (net.js:1415:7)
    at Function.listen (/home/app/node_modules/express/lib/application.js:618:24

However when looking at similar questions I was advised to find the process using the port and end it.

When running on root and regular user the following command:

lsof -n -i:80

as well as

netstat -tulpn | grep:80

I get 0 results and no output returned.

Killing the node daemon (using pkill node) and then restarting it didn't work either.

Changing the port gives the same error strangely:

Error: listen EADDRINUSE: address already in use :::8080

Why am I still getting this error?

EDIT The Server Code:

// optional: allow environment to specify port
const port = process.env.PORT || 80;

// wire up the module
const express = require("express");

var http = require("http");
var request = require("request");

// create server instance
const app = express();
// bind the request to an absolute path or relative to the CWD

app.use(express.static(path.join(__dirname, "../dist")));

app.use(express.json());

app.listen(port, () => {
  console.log(`This app is listening at http://localhost:${port}`);
});

...

Hi can you upload the server.js content. You have to run your http server in a other port or try to stop nginx or Apache2 service if you installed them

Simply Kill the Process:: sudo kill $(sudo lsof -t -i:8080)

where replace 8080 with your address and then rerun your app. If you want to know all the port or address in use simply install nmap from ubuntu snap store and scan all the port using terminal with command

nmap localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM