Json-server: Command to start json-server is not working.

Created on 27 Sep 2016  ·  32Comments  ·  Source: typicode/json-server

I am trying to start JSON server with following command
$ json-server --watch db.json

I am not able to start the server. I am getting command not found error

“json-server: command not found”

I referred
https://github.com/typicode/json-server
http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/

I am using iMac (Mid 2010) with latest OS (macOS Sierra) version 10.12

Please help me to resolve the issue. Thanks

Most helpful comment

npx json-server --watch db.json solved the problem for me

All 32 comments

Hi @KavyaKn

I would suggest double checking if the flag -g was set when running npm install -g json-server. It's usually a common mistake that results in command not found.

If it doesn't work, can you tell me what's your version of node and npm? What did you use to install Node?

Hi..
I had used the same command “npm install -g json-server”
The node and npm version which i am using is
node -> v6.6.0
npm - > 3.10.3

and i had downloaded the node from this URL
https://nodejs.org/en/

I'm having the exact same issue as well

node v6.7.0
npm v3.10.7

If you try to install another CLI tool, do you have the issue too? For example:

$ npm install --global gulp-cli
$ gulp

Yes i am getting the issue "-bash: gulp: command not found".
For the command
$ npm install --global gulp-cli
$ gulp

Thank you for the test.

I think it might be related to your Node installation actually. PATH may be missing some Node paths and so your terminal fails to find installed CLIs.

I've not tried Node installer on Sierra so I can't say much, but you can try reinstalling it or you can check if there's not something that is modifying PATH.

Personally, I like to use nvm and it works on Sierra.

Thank you very much. Reinstalling node with nvm worked for me

On Thursday, 13 October 2016, typicode [email protected] wrote:

Thank you for the test.

I think it might be related to your Node installation actually. PATH may
be missing some Node paths and so your terminal fails to find installed
CLIs.

I've not tried Node installer on Sierra so I can't say much, but you can
try reinstalling it or you can check if there's not something that is
modifying PATH.

Personally, I like to use nvm https://github.com/creationix/nvm and it
works on Sierra.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/typicode/json-server/issues/370#issuecomment-253481489,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVvu6AQ7M2L1aiq8JrpumZdLUxA-J0Wxks5qzg6PgaJpZM4KHvmB
.

Glad it worked :+1:
Is it ok for you too @KavyaKn?

Did you try sudo npm install -g json-server.
executing this as sudo solved issue for me (ubuntu 14.04, node installed without nvm)

[POSSIBLE SOLUTION]I had the same problem. Did the following steps.

  • installed JSON-Server with
    sudo npm install -g json-server

Tried to start the server in the same terminal
json-server db.json

Got the same error.

  • Started a fresh terminal and started the server and it worked fine.

I had this problem because my $HOME/.npm-global/bin was not in the $PATH.
Works for me.

export PATH=$PATH:$HOME/.npm-global/bin

tip: Is possible get json-server install in return message of npm install -g json-server command.

use "json-server db.json" db.json is my json file name replace it with your file name

I know this is rather old, but I had the same issue and got solved by installing json-server package globally, that's all.
Meaning, I run this command
npm install -g json-server
before running
json-server --watch db.json

I didn't have to re-install node or npm, or use nvm or anything else.

I have a problem that json server not working.
Error Showing: ERR! code ELIFECYCLE
Error Showing: ERR! errno 1
json-server --watch db.json not woking and showing error
i got the answer
while start json-server it compiling the db.json file and if any type mistake in db.json file it show the error

bash: json-server: command not found
am using windows 10 trying to use it on reactjs...Please help

fixed this by following the steps are being described here https://stackoverflow.com/questions/43465086/env-node-no-such-file-or-directory-in-mac

@iamgodswill
I am using Mac mini and was stuck in the same issue some days ago.
Try using _

sudo npm install -g json-server

👍
_

Hello, I'm building something that I wish someone could use without having to install json-server globally themselves.
Is there a way to make it so json-server would be ready to use as soon as the other person would download + npm install my app?

npx json-server --watch db.json solved the problem for me

да, с npx оно типо его запустило, но ничего он не подгружает, файл с базой видит отлично, а достучаться к нему нельзя
...оставил пока так как есть)...хоть запустился...

npx json-server --watch db.json solved the problem for me

This also helped me resolve the issue.
PS: I use Windows

npm install -g json-server --save has worked for me...... its good option

npx json-server --watch db.json solved the problem for me

Very helpful

npx json-server --watch db.json solved the problem for me

thanks for this!

Did you try sudo npm install -g json-server.
executing this as sudo solved issue for me (ubuntu 14.04, node installed without nvm)

this works for me, thank you!

Try sudo npm install -g json-server, it's work for me

This works npx json-server --watch db.json - thanks @abdelalimah

npx json-server --watch db.json solved the problem for me

Thank you @caprica-Six it is working for me.

npx json-server --watch db.json benim için problemi çözdü

Thank you @caprica-Six it's working

Мне помогла не локальная установка , а глобальная .

npx json-server --watch db.json solved the problem for me

Thank you so much. This works

I was trying to use it with Vue JS in Linux and came across the same issue:

  • npm install json-server
    It will install the package locally and inside the Vue project there is a node_modules folder and the executable is in .bin.
    So running the following command will work.
./node_modules/.bin/json-server --watch data/db.json

  \{^_^}/ hi!
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sboudouk picture sboudouk  ·  3Comments

shikaan picture shikaan  ·  3Comments

jasonlimantoro picture jasonlimantoro  ·  4Comments

pantchox picture pantchox  ·  3Comments

Isanderthul picture Isanderthul  ·  3Comments