Sometimes, when running nodemon or node server.js, you'll trigger one of the following errors:
Error: listen EADDRINUSE: address already in use :::3000
or
Port 3000 is already in use
[nodemon] app crashed - waiting for file changes before starting...
This usually means that either you have an app running on port 3000 in another terminal, or you closed your terminal without shutting down your server (ctrl + c).
In order to resolve this in Linux, begin by using this command:
lsof -i tcp:3000
This will return some info about any processes running on the port that follows tcp:
:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 3870 micahwierenga 23u IPv6 0xac33fe12a5a6a54d 0t0 TCP *:hbci (LISTEN)
The piece that we want to pay attention to is the PID (or Process ID). Take that number (if you have multiple rows, take the PID from the first row) and use it in the following command:
kill -9 3870
You will, of course, replace 3870
with the PID that is returned in your terminal.
This should stop that process so that you can start a new process (e.g., nodemon or node server.js on port 3000) on that port.