I am setting up a json-server and I install it and assign it to be my npm start command like so
"scripts": {
"start": "json-server -p 3001 -w db.json"
but every time I type npm start on the terminal I got this error
> [email protected] start C:\Work\React-projects\streams\api-server
> json-server -p 3001 -w db.json
'json-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `json-server -p 3001 -w db.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Abdelaziz\AppData\Roaming\npm-cache\_logs\2019-04-06T09_07_30_796Z-debug.log
Use npx to solve the error "json-server is not recognized as an internal or external command, operable program or batch file", e.g. npx json-server --watch db. json or install the package globally by running npm install -g json-server . The fastest way to solve the error is to use the npx command.
We just need to use the --port number flag. For example: json-server --watch db. json --port 3004.
json , you can change the port inside the lite-server module. Go to node_modules/lite-server/lib/config-defaults. js in your project, then add the port in "modules. export" like this.
First, you need to check json-server
installed globally or not. or you can install it globally by
npm install -g json-server
If you install it locally in your project, use npx
to run it
npx json-server --watch db.json
Checkout difference between npx and npm here: https://stackoverflow.com/a/52018825/11285186
First step you install the json server using the following command:
npm install -g json-server
Then, you can run the command and select the port using the following command:
npx json-server --watch -p 3333 server.json
Change 3333 to the port number you want and replace server.json with the name of your fake api.
In my case, I'm using React js and my server.json is at the root of my application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With