5

I just started using json-server and created a script, 'npm run server' to build it. However, when I try to access the JSON in my browser, I get "Access to localhost was denied".

Here's the script:

json-server --watch db.json --port 5000

enter image description here

Jordan Williams
  • 181
  • 2
  • 10
  • Check [this](https://superuser.com/questions/646304/google-chrome-cant-access-localhost-domains) thread out. TLDR: check what your server is actually listening on and what chrome is connecting to. Best to just set everything to `127.0.0.1:5000` – Mzapp Nov 27 '21 at 19:38

3 Answers3

7

I had the same issue with port 5000. I think it might be due to the port already being used by something else (if you're on a Mac, I believe it started with Monterey). I changed it to another port and it worked.

  • Yes, it's Monterey's AirPlay thing running on port 5000. More info in this answer: https://stackoverflow.com/a/69829313/3406483 – redOctober13 Mar 01 '22 at 21:02
3

It's due to the AirPlay receiver in Mac OS Monterey using port 5000. More details at this answer.

You can either disable AirPlay (System preferences --> Sharing), or start the server on another port in your package.json as mentioned:

--port 3000

redOctober13
  • 3,662
  • 6
  • 34
  • 61
1

Same, I just changed the port flag in the json script to 3000, re-ran the server and all good.

 "scripts": {
    "server": "json-server --watch db.json --port 3000"
  }
dmoncado
  • 11
  • 3