0

No other process runs on port 3000 except this

Here's the part of a program

const port = process.env.port || 3000;

app.listen((port), () => console.log(`listening to port ${port}`));

const io = require("socket.io")(port) //Here's the problem. 

Problem appears when I add port 3000

If I manually write some other port like 4000. It works

Shall I create another port for socket.io?

In case of port 3000

The error looks like this

listening to port 3000
events.js:292
      throw er; // Unhandled 'error' event
      ^

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

Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1345:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...

Sarah
  • 81
  • 7

2 Answers2

0

In the terminal try this to find the active port:

Windows

netstat -ano | findstr :3000

Mac/Linux

lsof -iTCP:3000 -sTCP:LISTEN

Then kill using the PID:

kill <PID>

or this if the above doesn't work

kill -9 <PID>
Zoe
  • 27,060
  • 21
  • 118
  • 148
Mikey Lau
  • 11
  • 3
0

It means that there is a process that uses 3000 port, try to kill that process and start the application again.