S
S
Sergey Burduzha2021-09-23 11:06:16
Node.js
Sergey Burduzha, 2021-09-23 11:06:16

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

This error appeared.
Earlier, as a protection, I found such a hack, insert into the package.json script

"predev": "fuser -k 3000/tcp && echo 'Terminated' || echo 'Nothing was running on the 3000'",


Now it doesn't work either.

I found the second option, add the following code to server/index.js, the start file for the server
async function start() {
  process.once("SIGUSR2", function () {
    process.kill(process.pid, "SIGUSR2");
  });
  const nuxt = await loadNuxt(isDev ? "dev" : "start");
  app.use(nuxt.render);
  if (isDev) {
    build(nuxt);
  }
  app.listen(PORT);
}

// Запуск приложения.
start();


process.once, I found this recommendation on the site npm nodemon.

And anyway, if I change the code in the server files, then an error appears.

HWZq3lX.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Burduzha, 2021-10-21
@serii81

The decision came by itself.
If you make any changes to the files on the server again 10 seconds after the error occurs, the error will disappear.

J
julandre, 2021-12-01
@julandre

The problem is solved by stopping pm2 before changing the code. pm2 stop 0 command.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question