DEV Community

Cover image for Error: listen EADDRINUSE: address already in use (JSON)
Kevin O'Shaughnessy
Kevin O'Shaughnessy

Posted on

Error: listen EADDRINUSE: address already in use (JSON)

THE PROBLEM

I began the Ramen Rater assignment for Flatiron School (essentially a lab focused around using GET, POST, PATCH for Postman) by running json-server --watch db.json     and I got the following error:

Some error occurred Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
    at Server.setupListenHandle as _listen2
    at listenInCluster (node:net:1788:12)
    at GetAddrInfoReqWrap.doListen as callback
    at GetAddrInfoReqWrap.onlookup as oncomplete {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 3000

With this error, I am not able to continue working on the lab (Postman). I researched this issue on Google, Stack Overflow, Slack, and Piazza. 

HOW TO FIX THIS

I booked a help session and was able to get help fixing this issue in 2 ways. The core issue was that port 3000 was already in use due to a previous lab still running. One of the ways to fix this is to run npx kill-port in the terminal.

Image description

This frees up the port and makes it available for running json-server --watch db.json and getting the API set up in Postman. 

A second way to solve this problem would be to find the process ID (PID) through entering lsof -i tcp:3000 in the terminal, then running kill -9 [process id number]. This will free up the port and allow one to run db.json.

Image description

Top comments (0)