I was following this tutorial to create and test a Node.js Express API and hosting it on Vercel:
I did everything as instructed. When I run vercel dev, I see the message “> Ready! Available at http://localhost:3000” but after a few seconds I get “Error: listen EADDRINUSE: address already in use :::3000” and the error keeps reappearing every few seconds, like it keeps restarting but finds the address already in use.
I did everything the same as in the tutorial, so I don’t know what’s going on?
Thanks for the suggestion!
I tried doing that, changing express to use port 3001:
app.listen(3001, () => {
console.log(‘Server started on port 3001’);
});
With that I no longer have any errors and I’m able to call the API.
However, in the console, I see the “Server started” message log being written multiple times (see attached image), in intervals of a few seconds, which doesn’t seem normal. Also, though the API works, depending on when I call it, sometimes it fails (I’m guessing if I hit at the right moment when it’s in one of the multiple restarts).
This also seems related to the original error, since I first got the OK message, then after a few seconds was getting the error repeatedly.
Any idea why this could be??
EDIT: Another information: when running the API locally using npx tsx, it works normally, without the repeated restart behavior.
If you run pfctl -s nat (probably need to run it with sudo). This should tell you if there’s any port forwarding set up on your computer. If 3001 is mapped to a port below 1024, you’d need sudo access to use it. If you don’t see 3001 anywhere in the output, it’s probably not the cause of your issue.
Also - can you try changing the port to other values (like 5000, 8080, etc)?
I’m running on Windows, so I think the equivalent would be running netstat -aon? I did it and port 3001 is not listed.
I tried with ports 5000 as suggested and the result is the same as with 3001, it works, but the console keeps showing the start message repeatedly, as if it kept continuously restarting.