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?
尝试:
npx json-server --watch db.json
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
Solution : For Linux:
Firstly, run this command to globally install json-server
sudo npm install -g json-server
Move to your local folder(like my-app) and run this command
npm install json-server
Open a new Terminal in the same folder
json-server --watch db.json --port 3004
I added the script for running the json-server in my package.json
file like this:
"server": "json-server db.json --watch --port 5000"
And tried to run it like this:
npm run server
And it works except the server wasn't being watched unless I had to manually end and run the json server command every time a change was made.
What fixed it for me was running the command directly in a bash terminal (under the app root directory).
So run:
json-server db.json --watch --port 5000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.