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.