Categories
JavaScript Answers

How to Fix the ‘Error: listen EADDRINUSE’ Error When Running a Node.js App?

Spread the love

Sometimes, we may run into the ‘Error: listen EADDRINUSE’ error when running a Node.js app.

In this article, we’ll look at how to fix the ‘Error: listen EADDRINUSE’ error when running a Node.js app.

Fix the ‘Error: listen EADDRINUSE’ Error When Running a Node.js App

To fix the ‘Error: listen EADDRINUSE’ error when running a Node.js app, we should make sure that no process is running on the same port that the Node.js app is running on.

For instance, if we have the following Express app code:

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('hello world')
});

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

Then we should make sure that no process is running on port 3000 before we run our Express app.

Conclusion

To fix the ‘Error: listen EADDRINUSE’ error when running a Node.js app, we should make sure that no process is running on the same port that the Node.js app is running on.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *