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

14,520

Solution 1

Try:

npx json-server --watch db.json

Solution 2

Check if this might help you.

Open the git bash(assume you have on your local machine) and execute below command: alias json-server="<..../node_modules/.bin/json-server.cmd>" ---> IGNORE <, > symbols and .... is the location where your node_modules folder is present

Then run json-server --watch db.json

Share:
14,520
Angelo Fonseca
Author by

Angelo Fonseca

Updated on June 12, 2022

Comments

  • Angelo Fonseca
    Angelo Fonseca almost 2 years

    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?

  • Marco
    Marco over 3 years
    this helped me - but why?
  • Alexander Cherednichenko
    Alexander Cherednichenko about 2 years
    this way with npx also works for me 👍