3

I already installed in other computers by npm the json-server. But on my MacBook Pro the command was run with successful and when I will execute the command json-server db.json is showed the message:

Errors Screenshot enter image description here

My versions:

node -v and npm -v enter image description here

James Wong
  • 4,529
  • 4
  • 48
  • 65
Andre Conjo
  • 41
  • 1
  • 8

4 Answers4

1

I did fix this following these steps:

https://gist.github.com/rcugut/c7abd2a425bb65da3c61d8341cd4b02d

Andre Conjo
  • 41
  • 1
  • 8
0

I was having the same problem. Previously, I named the folder as json-server (same as the package name) I changed the folder name and installed the package globally using npm install -g json-server It works perfectly fine now

Suraj Ingle
  • 372
  • 4
  • 18
0

Made the same mistake using VS Code. Entered in terminal->>

$ json-server --watch data/db.json <<-

Got the classic ->>

Error: ENOENT: no such file or directory, open 'data/db.json' <<- 

Simple fix was to realize I needed to add the parent folder name in the terminal ->>

$ json-server --watch folder-name/data/db.json <<- 

This opened a local host to my db.json file ->>

http://localhost:3000/projects <<- 

Hope this helps someone that made the same simple mistake I did.

Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
-1

I too got this issue. while working on a frontend project(vue).
I don't know why it happens but I found a way around / solution.

go to your pakage.json file. go to "scripts" and add

   "scripts": {
     "fakeDB":"json-server --watch db.json"
 },

you can change "fakeDB" to what ever you want and "json-server --watch " is used to run your json db file in my case its db.json