So you cloned your Node or Webpack project, run that
npm run start then get confronted with a nasty error message, something like
Error: Listen EADDRINUSE or
Error: Listen EACCES. Let's first discuss why you're seeing this error message then talk about how to solve it.
When you run a local HTTP server, the server will attempt to listen for incoming network request and traffic on a single port. Only one process on your computer can use a port at any given time. With this in mind, the error you saw (
EADDRINUSE) might make more sense - it can be read as "error, the address or port you asked me to use is already in use". The two solutions below will allow you to either stop the process that is using that port, or change the port that your server is attempting to use.
Find out what process is already using this port then kill it.
lsof -i tcp:<yourport>. For example,
lsof -i tcp:8080. This will tell you the process that is currently using this port. Note the number under the "pid" column. In this case, the PID is 69498
killall <pid>, so
Solution #1 is a bit destructive - it forcibly kills the other process that is using the given port. Solution #2 will instead change the port you're attempting to use. Fixing the error with this solution will be slightly different depending on whether you're attempting to troubleshoot a general Node server or a webpack server. Here's the steps for webpack dev server:
devServer. If it doesn't exist, create it. You're looking for something like this:
port: 8081, or whatever port you want to move your webpack dev server to use. Your
webpack.config.jsfile should now look like this:
npm run start.
localhost:8081. If you changed the dev server to use a port other than
8081, then you'll update the URL accordingly. For example, if you changed the port to
4172, then visit