Error listen eaddrinuse address already in use 5000

I am trying to run a nodes app. I run node app.js. When I do, I get this error: node:events:346 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE: address already in use :::

I am trying to run a nodes app. I run node app.js. When I do, I get this error:

node:events:346
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1311:16)
    at listenInCluster (node:net:1359:12)
    at Server.listen (node:net:1446:7)


Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1338:8)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}

I spent hours looking at possible solutions online but none have worked so far. Same codebase works great on a different machine. This error happens on Mac M1 chip.

Does anybody have any idea how to fix this?

I tried finding processes running on 5000, I tried to kill them etc… nothing worked so far. I am running node 15.14.0.

I am on a M1 Chip, running macOS Monterey

How can I fix this error?

I came across variants of this issue many times without ever being able to replicate it deterministically. But on all cases, I have found that…

  • Killing the port-process ${port} on the nodemon events start, restart or crash, does not solve my problem.
  • Synchronously killing it right before calling .listen(...) on my express app does not solve my problem.
  • However, asynchronously killing it before calling .listen(...) in a .then() does solve my problem, when…
    • …either fuser -k ${port}/tcp and npx kill-port ${port} is used to kill the port-process.
    • …the nodemon restart is delayed (hint: to delay it, merge your current nodemon.json with {delay: ${milliseconds}}). I have the solution below running almost all of the times with {delay: "500"}.

I have written a brief code snippet that does the job of killing the conflicting port-process at run-time, using fuser. I don’t think adapting the code so as to use npx kill-port ${port} would be very hard: I would appreciate if anyone could augment my code with that adaptation :)

Basically, one call of killPort keeps killing all the port-processes that hold onto the port ${port} until no processes are left. Finally, an interval is set so that if a round of killPort has killed any process, it checks again after some time. This killing and re-killing was done because for some reason the conflicting port-processes would get killed once but the error EADDRINUSE would still show up. It may be overkill, pun intended, but to be honest, it works, and I’m happy because of that.

Here it is, along with my current use case and its output:

import {execSync} from 'child_process';

const buildKillPortPromise = (port: number) => new Promise(
    (resolve) => {
      const killPort = () => {
        let hasKilled = false;
        while (true) {
          const pid = execSync(
              `fuser -k ${port}/tcp || echo '---'`, // fuser exits with 1 when no process has been killed
              {stdio: ['ignore', 'pipe', 'ignore']}, // https://nodejs.org/api/child_process.html#child_process_options_stdio
          ).toString().trim();
          if (pid !== '---') {
            hasKilled = true;
            console.log(`PID ${pid} was holding onto port ${port}. It was killed.`);
          } else {
            return hasKilled;
          }
        };
      };
      const intervalId = setInterval(() => {
        if (!killPort()) {
          clearInterval(intervalId);
          resolve(undefined);
        }
      }, 500); // this is the minimum that I have found that works consistently
    },
);

Use case:

export class HttpEntrypoint {
  // ...
  start(): Promise<void> {
    return this.setup() // this.app.use(morgan('combined')) and other stuff
        .then(() => buildKillPortPromise(this.config.port))
        .then(
            () => new Promise(
                (resolve) => {
                  this.server = this.app.listen(
                      this.config.port,
                      () => resolve(undefined),
                  );
                },
            ),
        )
        // .then(() => console.log(`Started listening at ${port}`));
        // ^ this goes outside of this class:
        // await entrypoint.start().then(() => console.log(...))
  }
}

Output:

> nodemon

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src/**/*
[nodemon] watching extensions: ts
[nodemon] starting `ts-node src/index.ts`
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19286 was holding onto port 8420. It was killed.
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19391 was holding onto port 8420. It was killed.
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19485 was holding onto port 8420. It was killed.
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19663 was holding onto port 8420. It was killed.
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19834 was holding onto port 8420. It was killed.
Started listening on 8420
[nodemon] restarting due to changes...
[nodemon] starting `ts-node src/index.ts`
PID 19942 was holding onto port 8420. It was killed.
Started listening on 8420

Hello Guys, How are you all? Hope You all Are Fine. Today I am just run my nodejs Project with nodemon but I am facing following error Nodemon: Error: listen EADDRINUSE: address already in use :::5000 in nodejs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

Contents

  1. How Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error Occurs ?
  2. How To Solve Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error ?
  3. Solution 1
  4. Solution 2
  5. Solution 3
  6. Solution 4
  7. Summery

I am just run my nodejs project with nodemon but facing the following error in my stack track.

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

How To Solve Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error ?

  1. How To Solve Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error?

    To Solve Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error Just make sure You might have other instances of the terminal that is already running your node server. If you are using Visual Studio Code, check your terminals.

  2. Nodemon: Error: listen EADDRINUSE: address already in use :::5000

    To Solve Nodemon: Error: listen EADDRINUSE: address already in use :::5000 Error Just make sure You might have other instances of the terminal that is already running your node server. If you are using Visual Studio Code, check your terminals.

Solution 1

Just make sure You might have other instances of the terminal that is already running your node server. If you are using Visual Studio Code, check your terminals.

Solution 2

--delay helped me to fix both of issues

  • on auto-restart
  • stopping with ctrl-cnodemon --delay 500ms app.js

Solution 3

You can try running your server on some other port like 3000.

If you still want to use the same port, then you can use the following command to get the list of the running processes on that particular port:

lsof -i tcp:3000 

Use following command in terminal to kill that running port

sudo kill -9 $(lsof -i tcp: 3000 -t)

Solution 4

I used this to fix the same problem

process.once('SIGUSR2', 
  function () { 
    process.kill(process.pid, 'SIGUSR2'); 
  }
);

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

  • SyntaxError: invalid syntax to repo init in the AOSP code.


By Chris Mendez
in
NodeJS

Nov 14, 2017

If you’re using NodeJS, sometimes you’ll get an error like this:

Error: listen EADDRINUSE :::5000
    at Object.exports._errnoException 
    at exports._exceptionWithHostPort 
    at Server.setupListenHandle [as _listen2]
    at listenInCluster 
    at Server.listen 
    at Function.app.listen 

What this error means is that you’re trying to bind the app but the server is already in use. The only way to to first kill the server. Here’s how:


Process Scanning

You can always use good ol’ grep to find which process is already running. First run process then use grep to filter out any process that has the name «node». This command contains an extra grep -v grep so that it ignores the grep process.

Method 1

ps | grep node | grep -v grep

Method 2

ps -ax | grep node

Port Scanning

Method 1

You can search using the tcp port.

lsof -i tcp:5000

Method 2

You can also use netstat with grep to find the process with the port.

netstat -punta | grep 5000

Stop Process

Once you find the culprit, look for the PID. This is a number you will use to stop the process.

kill -9 <PID number>

Published on July 23, 2022 by Peter Thaleikis

Some errors are easy and simple. Quick fixes you get resolved in minutes. Others aren’t and you got to dig in for much longer than you would like to. This was one of these for me. I’m sharing my solution here to make it a bit easier for other developers.

This problem seems to affect especially Linux users like myself. I can’t confirm this for sure as I run only Linux 🐧️ On my elementary the issue usually comes up when I try to run npm/yarn commands which are supposed to watch file changes (e.g. CSS/SCSS or JavaScript files). The problem affects all frameworks from VueJS, to React and Angular. The related dev— and prod-commands work fine. It’s only affecting watch-command and appears to be linked to a file-system incompatibility when watching file changes.

This particular case problem arises while using my swiss armyknife build tool Laravel Mix on a project. When running npm run watch (actually yarn watch) I get this error message after the compile step is finish:

events.js:292
      throw er; // Unhandled 'error' event
      ^

The line number depends on the exact libraries used in the project, but the events.js filename or throw er; // unhandled 'error' event are usually part of the error.

If supported, watch-poll often resolves the issue. But some libraries, like my starter for eleventy (this blog), aren’t supporting poll and I needed to resort to a different approach. After spending some time researching and trying I’ve found a solution which works for now. I remove the node_modules-folder (rm -rf node_modules) and force-clear the NPM cache (npm cache clear --force) before reinstalling the node dependencies. Summarized in the following steps:

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install

Please note: This removes also the lock-file. Thereby updating your project, make sure to test everything before you push the changes to production 🙏️

Update #1: Solution: Stop all other «watch»-processes

If you have a number of node processes running this might be part of your issue. I’ve noticed the problem coming up more often if I’ve got a number of watch processes (for other projects) running. After stopping these and clearing the files as described above the issues was resolved.

Update #2 (2020-03-04): Error: ENOSPC: System limit for number of file watchers reached, watch ‘src/assets’

With a recent update of my dependencies, I’ve noticed a new, better understandable wording for the known error. This points you much faster in the right direction. Again, I’ve been able to resolve the issue using the approach mentioned above.

Update #3 (2020-04-23): Increase allowed file handles

By chance I stumbled across a solution to increase the number of allowed file handles. This actually came with my recent trail of Microsoft Studio Code for Linux. It thrown a familiar sounding error:

Visual Studio Code is unable to watch for file changes in this large workspace (error ENOSPC)

Microsoft recommended the following to increase the number of allowed file handles. You can do by updating your /etc/sysctl.conf file. The detail steps are lined out here.

Update #4: Do you prefer a video?

More a video guy? Someone also made a video based on the content of article:

Update #5:

This might also come with a blocked port an app is try to listen to. In this case your error message might look like this:

node:events:505 throw er; // unhandled 'error' event ^ error: listen eaddrinuse: address already in use :::5000

The port at the end, here 5000, can vary.

If this looks like your problem, you might want to check what is listening on the port in question. Simply open the port with port, e.g. localhost:5000, in your browser. After turning of the application in question or changing your port this problem should be resolved.

By the way

I love the web and building stuff! The web still has lots amazing open-source libraries and actually innovative side-projects. Once in a while, I share these awesome web-findings via email. If this sounds like something you are into, subscribe below:

Published under the following tags: JavaScript Linux

Dung Do Tien Jul 22 2022 300

Hi you guys. I am a beginner in Nodejs and today I tried to create a small app, I want to call an API and display all data as a table in the browser.

My server.js file

 import fetch from "node-fetch";
import express from "express";
var app = express();

app.get('/', async (req, res) =>  {
        const result = await getUser();
        console.log(result);
});

var server = app.listen(5000, function () {
    console.log('Server is running..');
});


async function getUser() {
   try {
      const response = await fetch('https://randomuser.me/api/');
  
      if (!response.ok) {
        throw new Error(`Error! status: ${response.status}`);
      }
  
      const result = await response.json();
      return result;
   } catch (err) {
     console.log(err);
   }
}

I run the app by using the command node server.js but I got an exception throw Error: listen EADDRINUSE: address already in use :::5000. You can see detail here:

 C:UserscontasourcereposNodeJsDemo1>node server.js
node:events:505
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1372:16)
    at listenInCluster (node:net:1420:12)
    at Server.listen (node:net:1508:7)
    at Function.listen (C:UserscontasourcereposNodeJsDemo1node_modulesexpresslibapplication.js:635:24)
    at file:///C:/Users/conta/source/repos/NodeJs/Demo1/server.js:10:18
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1399:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 5000
}

I am using Node version 16.15.1

Thank you for any suggestions.

Have 2 answer(s) found.

  • Elsen Askerov
    Jul 22 2022

    The error: listen EADDRINUSE: address already in use :::5000 occurs because port 5000 is being used by another app. 

    Solution: You can change port 5000 to another port (ex: 5001).

    Change

     var server = app.listen(5000, function () {
        console.log('Server is running..');
    });

    To

     var server = app.listen(5001, function () {
        console.log('Server is running..');
    });

    This is a fast solution to solve it. 

  • You can kill port 5000 before using it. To kill port 5000 you can follow this:

    First, you would want to know which process is using port 5000

    This will list all PID listening on this port, once you have the PID you can terminate it with the following:

    And then you can rerun your app.

    I hope this work for you.

Содержание

  1. How to kill server when seeing “EADDRINUSE: address already in use”
  2. The Problem
  3. The cause behind this issue
  4. Solution
  5. Kill the process manually
  6. For Mac/Linux
  7. For Windows
  8. Enjoy!
  9. Level Up Coding
  10. Fixing nodemon ‘Error: listen EADDRINUSE: address in use’
  11. Has this ever happened to you?
  12. Luckily there is a solution!
  13. Save this command for future use
  14. The quick and easy way to save
  15. The slightly more advanced way to save
  16. How to kill server when seeing “EADDRINUSE: address already in use”
  17. The Problem
  18. The cause behind this issue
  19. Solution
  20. Kill the process manually
  21. For Mac/Linux
  22. For Windows
  23. Enjoy!
  24. Level Up Coding
  25. Error: listen EADDRINUSE: address already in use . 5000 #1849
  26. Comments
  27. Expected behaviour
  28. Actual behaviour
  29. Steps to reproduce

How to kill server when seeing “EADDRINUSE: address already in use”

A tutorial on how to kill the process manually when “EADDRINUSE” happens on Mac/Linux and Windows.

The Problem

When trying to restart a Node application, the previous one did not shut down properly, and you may see a “ listen EADDRINUSE: address already in use” error such as:

The cause behind this issue

The reason behind this is that

process.on(‘exit’, . ) isn’t called when the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event.

Solution

The proper fix for the application would be

  • On crash, do process.on(‘uncaughtException’, ..)
  • And on kill do process.on(‘SIGTERM’, ..)

When this EADDRINUSE issue has already happened, in order to resolve it, you need to kill the process manually. In order to do that, you need to find the process id (PID) of the process. You know the process is occupying a particular port on your machine or server.

Kill the process manually

For Mac/Linux

To find the process id (PID) associated with the port

Then to kill the process

Use -9 option to make sure the process dies immediately

If you get permissions errors, you may need to use the sudo keyword, for example:

For Windows

Solution 1: Task Manager

Open the Task Manager application ( taskman.exe), from either the Processes or Services tab sort by the PID column. To display the PID column, right-click the header row and select PID from the list. Right-click the process you want to stop and select End task.

Solution 2: Use Command prompt

Open a CMD window in Administrator mode by navigating to Start > Run > type cmd > right-click Command Prompt, then select Run as administrator.

Use the netstat command lists all the active ports. The -a switch displays all ports in use, not just the ports associated with the current user. The -n option stops a hostname lookup (which takes a long time). The -o option lists the process ID that is responsible for the port activity. The findstr command matches the header row that contains the PID string, and the port you are looking for, in a port format with the preceding colon, is :3000.

To kill this process (the /f is force):

Enjoy!

And that’s about it. Thanks for reading

Level Up Coding

Thanks for being a part of our community! Level Up is transforming tech recruiting. Find your perfect job at the best companies.

Источник

Fixing nodemon ‘Error: listen EADDRINUSE: address in use’

Has this ever happened to you?

You go to start up your server with npm start and you get the below error message

Exit fullscreen mode

Luckily there is a solution!

This error occurs when a process is already running on the port you’re trying to use. All you need to do is kill that process. In this case, since the port we want to use is 3000 we could simply paste and execute the below code in our terminal.

Exit fullscreen mode

This will kill the process running on port 3000 and you should be good to start your server with npm start like usual.

Save this command for future use

If this happens often, it’s a great idea to add an alias to bash for reuse anytime. The below code is a function that accepts a port number to kill and when saved can be reused for any port number.

Exit fullscreen mode

The quick and easy way to save

Simply execute the below command and the killport function will be available every time you open bash. Just remember to restart your terminal for the saved function to be loaded after first adding it.

Exit fullscreen mode

Below is an example of how the newly defined killport function can be used to kill a process on port 3000.

Exit fullscreen mode

The slightly more advanced way to save

To save this function alongside your other bash aliases and configurations you just need to add the below code to

/.bash_aliases which can be accomplished using vim

/.bashrc and pasting in the code snippet.

Источник

How to kill server when seeing “EADDRINUSE: address already in use”

A tutorial on how to kill the process manually when “EADDRINUSE” happens on Mac/Linux and Windows.

The Problem

When trying to restart a Node application, the previous one did not shut down properly, and you may see a “ listen EADDRINUSE: address already in use” error such as:

The cause behind this issue

The reason behind this is that

process.on(‘exit’, . ) isn’t called when the process crashes or is killed. It is only called when the event loop ends, and since server.close() sort of ends the event loop (it still has to wait for currently running stacks here and there) it makes no sense to put that inside the exit event.

Solution

The proper fix for the application would be

  • On crash, do process.on(‘uncaughtException’, ..)
  • And on kill do process.on(‘SIGTERM’, ..)

When this EADDRINUSE issue has already happened, in order to resolve it, you need to kill the process manually. In order to do that, you need to find the process id (PID) of the process. You know the process is occupying a particular port on your machine or server.

Kill the process manually

For Mac/Linux

To find the process id (PID) associated with the port

Then to kill the process

Use -9 option to make sure the process dies immediately

If you get permissions errors, you may need to use the sudo keyword, for example:

For Windows

Solution 1: Task Manager

Open the Task Manager application ( taskman.exe), from either the Processes or Services tab sort by the PID column. To display the PID column, right-click the header row and select PID from the list. Right-click the process you want to stop and select End task.

Solution 2: Use Command prompt

Open a CMD window in Administrator mode by navigating to Start > Run > type cmd > right-click Command Prompt, then select Run as administrator.

Use the netstat command lists all the active ports. The -a switch displays all ports in use, not just the ports associated with the current user. The -n option stops a hostname lookup (which takes a long time). The -o option lists the process ID that is responsible for the port activity. The findstr command matches the header row that contains the PID string, and the port you are looking for, in a port format with the preceding colon, is :3000.

To kill this process (the /f is force):

Enjoy!

And that’s about it. Thanks for reading

Level Up Coding

Thanks for being a part of our community! Level Up is transforming tech recruiting. Find your perfect job at the best companies.

Источник

Error: listen EADDRINUSE: address already in use . 5000 #1849

  • nodemon -v : 2.0.7
  • node -v : 14.16.01
  • Operating system/terminal environment: MacOS Big Sur
  • Using Docker? No
  • Command you ran: nodemon server

Expected behaviour

Close port before reinitializing server.

Actual behaviour

Steps to reproduce

  1. Initialize app (basic MERN app)
  2. Save any file.
  3. Error is thrown.

This only started happening after I updated my Mac to Big Sur. I can circumvent this issue by either stopping the app and killing the port or by saving a second time a couple of seconds after the first crashed the server.

The text was updated successfully, but these errors were encountered:

Can you explain and provide example code? Because I’m pretty sure «basic» actually means: set up mongodb, add nginx, possibly webpack and a bunch others. i.e. not compatible with «basic».

If you can provide code that replicates this issue, happy to look at it. Otherwise this is too vague.

server.js roughly looks like this:

Okay, start striping the code back until you have the bare minimum and you can still replicate, then post that here, then we can take a look.

I’ve recently started facing the same issue on my own application. Nodemon was working fine all this while but now seems to be leaving a single Node process listening on an open port (3000, in my case). I looked up past issues on the GitHub repo and found that the most popular one had been closed last year.

My stripped-down entry file (app.js) looks like this:

As for other environment and version info:

  • Node.js: v15.14.0
  • Nodemon: 2.0.7
  • Express: 4.17.1
  • OS: Ubuntu 20.04.2 LTS on Windows 10 (WSL 2)

Right now, I’m forced to manually kill the running process myself and restart the Node server, which defeats the purpose of using Nodemon at all. Any help is appreciated.

I’ve found a temporary work-around, the steps for which are listed below:

  1. Install the NPM kill-port package as a development dependency: npm install -D kill-port
  2. Create a new file in your project’s root directory called nodemon.json and paste in the following JSON (edit the port numbers below from 3000 to whatever port you’re using for your Node.js app):
  1. Add the following NPM script to your package.json file (if you haven’t already):

All credit goes to Tudor Constantin on Stack Overflow. However, it is a bit tedious and definitely a workaround, not something that should be done for all future Node.js projects.

Correction: The method I’ve shown above provides inconsistent results, and shouldn’t be considered a fix. It only works half of the time, and also occasionally crashes when Nodemon restarts.

Back to the drawing board.

I came across variants of this issue many times without ever being able to replicate it deterministically. But on all cases, I have found that.

  • Killing the port-process $ on the nodemon events start , restart or crash , does not solve my problem.
  • Synchronously killing it right before calling .listen(. ) on my express app does not solve my problem.
  • However, asynchronously killing it before calling .listen(. ) in a .then() does solve my problem, when.
    • . either fuser -k $/tcp and npx kill-port $ is used to kill the port-process.
    • . the nodemon restart is delayed (hint: to delay it, merge your current nodemon.json with > ). I have the solution below running almost all of the times with .

I have written a brief code snippet that does the job of killing the conflicting port-process at run-time, using fuser . I don’t think adapting the code so as to use npx kill-port $ would be very hard: I would appreciate if anyone could augment my code with that adaptation 🙂

Basically, one call of killPort keeps killing all the port-processes that hold onto the port $ until no processes are left. Finally, an interval is set so that if a round of killPort has killed any process, it checks again after some time. This killing and re-killing was done because for some reason the conflicting port-processes would get killed once but the error EADDRINUSE would still show up. It may be overkill, pun intended, but to be honest, it works, and I’m happy because of that.

Here it is, along with my current use case and its output:

Источник

This quick article shows you how to solve a common error you might confront when working with Node.js.

The Problem

When developing a Node.js application (with Express.js), I sometimes fall into the following problem:

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

Full error message:

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1380:16)
    at listenInCluster (node:net:1428:12)
    at Server.listen (node:net:1516:7)
    at Function.listen (/Users/goodman/Desktop/Projects/kindacode/api/node_modules/express/lib/application.js:635:24)
    at server (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:60:7)
    at bootstrap (/Users/goodman/Desktop/Projects/kindacode/api/src/index.ts:73:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 3000
}

The console message indicates that I am trying to run my app with a port being used by some program. This happens after my app crashes. Behind the scene, it’s very likely that there is a terminal window hiding out in the background that is still running the app. If you encounter the same problem as mine, don’t panic. Below is the solution.

The Solution

What we have to do is really simple: kill the process that is running on the port. Execute the command below:

npx kill-port 3000

If you need to free a port other than 3000, run the command above on that port. It’s also possible to terminate multiple ports at once:

npx kill-port 3000 4000 5000 6000 7000

Another solution that can solve this problem, as well as many others, is just restarting your computer (you even don’t have to do that in this situation).

That’s it. Further reading:

  • Node.js: Turn a Relative Path into an Absolute Path
  • Nodemon: Automatically Restart a Node.js App on Crash
  • 2 Ways to Set Default Time Zone in Node.js
  • 7 Best Open-Source HTTP Request Libraries for Node.js
  • Node.js: Use Async Imports (Dynamic Imports) with ES Modules

You can also check out our Node.js category page for the latest tutorials and examples.

Понравилась статья? Поделить с друзьями:
  • Error listen eaddrinuse address already in use 3001
  • Error listen eaddrinuse address already in use 3000 ubuntu
  • Error listen eacces permission denied
  • Error list was not declared in this scope
  • Error list visual studio