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
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
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.
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
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"
}