Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command json-server --watch db.json is not working - it returns"'json-server' command not found"

I set a JSON file to use as a little practice database, but I can't run the server.

I've already tried to install (and reinstall) json-server global and locally npm install -g json-server and npm install json-server and then run json-server --watch db.json, but it doesn't work.

I've also tried to set a script in the package.json file "load": "json-server --watch db.json" and run the script node load.

But nothing seems to work and I keep getting in return the message:

"'json-server' command not found"

or, in Portuguese:

"'json-server' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes".

How can I fix this?

like image 306
Angelo Fonseca Avatar asked Dec 03 '22 10:12

Angelo Fonseca


2 Answers

Try:

npx json-server --watch db.json
like image 187
Cristian Mora Avatar answered Dec 27 '22 07:12

Cristian Mora


Solution: For Linux:

  1. Firstly, run this command to globally install json-server

    sudo npm install -g json-server

  2. Move to your local folder(like my-app) and run this command

    npm install json-server

  3. Open a new Terminal in the same folder

    json-server --watch db.json --port 3004

like image 43
adithan bs Avatar answered Dec 27 '22 06:12

adithan bs