Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json-server is not recognized as an internal or external command

Tags:

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

like image 681
Abdelaziz Mohamed Avatar asked Apr 06 '19 09:04

Abdelaziz Mohamed


People also ask

How do you fix json server is not recognized as an internal or external command operable program or batch file?

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.

What is the command to run json server?

We just need to use the --port number flag. For example: json-server --watch db. json --port 3004.

How do I run a json server on another port?

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.


2 Answers

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

like image 145
namth Avatar answered Oct 21 '22 19:10

namth


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. enter image description here

enter image description here

like image 29
Everton Sales Avatar answered Oct 21 '22 18:10

Everton Sales