0

I am getting an error message:

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

When I tried after removing the server starting code(i.e app.listen part) nothing is happening

const path = require('path')
const express = require('express') 
//var publicPathDirectory = path.join(__dirname,"../public")
const app = express()
app.listen(3000,()=>{
    console.log('server started')
})

process.on('SIGINT', function() {
    console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
    // some other closing procedures go here
    process.exit(1);
  });
Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46
gst
  • 25
  • 4
  • 1
    Your port 3000 is being used by some other process. The simple fix would be to change the port number. This can be done by changing the 3000 in `app.listen(3000,()->{` line to some other number say 3001 or 3002 or even 4000. The proper way to actually fix this would be to find out the program using your port 3000 and evaluating if it is required to be run parallelty or not. https://helpdeskgeek.com/networking/determine-open-and-blocked-ports/ (refer to that to check for used ports in windows). – Y4glory Apr 17 '20 at 06:24
  • Thank You , after changing the port to 3001,it is working but how to stop the server on port 3000 – gst Apr 17 '20 at 07:41
  • Which OS do you run on? – Y4glory Apr 17 '20 at 08:21
  • @Y4glory,Windows 7 – gst Apr 17 '20 at 08:41
  • Thank You for your support but i have fixed my issue using command netstat -ano | find "LISTENINIG" find "3000" to get the pid and then taskkill /pid PID_NO /f to kill the process forcefully – gst Apr 17 '20 at 08:44
  • Hey thats good, I was going to suggest the same thing for windows – Y4glory Apr 17 '20 at 08:55

2 Answers2

1

Use number 1 inside exit only when you have an exit with failure. To force exit do not use number inside exit().

process.exit()

Please take a look at here. May be you can understand. link

Suman Kumar Dash
  • 681
  • 5
  • 19
0

I've had this happen to me before, where even though I quit the node server with CTRL+C, it still is hogging port 3000. You can kill node with:

pkill -f node

Potentially related to Node.js Port 3000 already in use but it actually isn't?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
  • pkill is not a recognized as an internal or external command error i am getting – gst Apr 17 '20 at 07:42