Back End Development and APIs Projects - Port already in use

Hi,

I’m using gitpod for Back End Development and APIs Projects.
But I keep getting an error every time I run npm run start:

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

This error is causing all the tests to fail.

I tried:

lsof -i :3000

And found that only gitpod is using port 3000.

I know I can change the port to 3001 or any random port to make the tests pass, but could anyone please explain what’s happening?

Thank you.

You have to stop the server first Ctrl + C

On first run it starts automatically, so if you open a new terminal and try to start the server the PORT will be in used.


I would suggest adding the --watch flag to the start script so it auto restarts on file save.

"start": "node --watch index.js"

I tried Ctrl + C and also attempted to close Gitpod and restart it.
The --watch flag seems very useful, I’ll use it for my projects. Thanks.

Did you stop it from the initial terminal that is opened?

Because if you just open a new terminal you can’t stop the server from that, and if you start the server from a new terminal before stopping it in the initial terminal, the server is still running from that initial terminal.

The error you are getting is because the server is still running when you try to start it.

Edit: Also, you can stop the workspace from the menu at the top left, the menu item is “Gitpod: Stop Workspace”