How to use json server with reactjs?

Viewed 1544

I've installed json-server by using:

npm install -g json-server

then I created a db.json like this:

{
  "employees": [
    {
      "id": 1,
      "first_name": "Sebastian",
      "last_name": "Eschweiler",
      "email": "sebastian@codingthesmartway.com"
    },
    {
      "id": 2,
      "first_name": "Steve",
      "last_name": "Palmer",
      "email": "steve@codingthesmartway.com"
    },
    {
      "id": 3,
      "first_name": "Ann",
      "last_name": "Smith",
      "email": "ann@codingthesmartway.com"
    }
  ]
}

I watch json-server by:

json-server --watch db.json 

but it does not work. The message in terminal is:

cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

What happened?

1 Answers

You can install json-server as a dev dependency

npm install -D json-server

then you can run the below command

npx json-server --watch db.json --port 3004

It will work.

Related