How To Fix "Error: Listen EADDRINUSE" and "Error: Listen EACCES"

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.

Why Do You See This Error, Anyways?

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.

Solution #1 (OSX):

Find out what process is already using this port then kill it.

  1. Figure out what port your app is trying to use. This is usually shown in the error message. In this screenshot, the port is everything after the colon (:), so 4172.
  2. Use the port to figure out what process is currently running on your given port. You can do this by opening a terminal window and running 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
  3. Kill this running process. Run killall <pid>, so killall 69498.
  4. All done!

Solution #2 (OSX or Windows)

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:

  1. In your project directory, open up the webpak.config.js file.
  2. Find a section in the config object called devServer. If it doesn't exist, create it. You're looking for something like this:
  3. Add in the keyvalue pair of port: 8081, or whatever port you want to move your webpack dev server to use. Your webpack.config.js file should now look like this:
  4. Start your server up! Starting the server will be slightly different, but usually it will use a command like npm run start.
  5. Open the server up. In your browser, navigate to 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 localhost:4172.
Previous Post Next Post