Address already in use error

Question:
unable to run my express code. Any port I use, I get “Address already in use” error
Repl link:
https://replit.com/@apoorvashirikan/Nodejs

const express = require('express');
const app = express();
let indexRouter = require('./routes/indexRouter.js')

app.set("views","views")
app.set("view engine", "ejs")

app.use('/', indexRouter)
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(express.static('public'))

const port = 3005

app.listen(port, () => {
  console.log(`server running on port ${port}`)
})

Hi @apoorvashirikan , welcome to the forums!
Try switching the port to another number and try again.

It seems that they already tried that:

1 Like

Hi, I tried with several port numbers. It doesn’t seem to work. For reference, this is the error I’m getting
node:events:492
throw er; // Unhandled ‘error’ event
^
Error: listen EADDRINUSE: address already in use :::5000

1 Like

Try running lsof -i tcp:5000 in the shell to see which process is using port 5000.

thanks everyone. The error was because I was already running the application on shell using (npm start) and then was trying to run again using the “Run” option. :sweat_smile: thanks again everyone for the assistance !!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.