Configuring package.json

Next, we need to adjust our package.json file, in order to start the server, in addition to our client (running via webpack-dev-server).

Let's start adjusting the package.json file:

  1. First, we create a new package script called start:server, by inserting it in the scripts section of the package.json file. We also make sure that we change the port, so that it does not run on the same port as our client:
    "scripts": {
"start:server": "npx json-server --watch server/db.json --port 4000",
"start": "react-scripts start",
  1. Then, we rename the start script to start:client:
    "scripts": {
"start:server": "npx json-server --watch server/db.json",
"start:client": "react-scripts start",
  1. Next, we install a tool called concurrently, which lets us start the server and the client at the same time:
> npm install --save concurrently
  1. Now, we can define a new start script by using the concurrently command, and then passing the server and client commands as arguments to it:
    "scripts": {
"start": "npx concurrently "npm run start:server" "npm run start:client"",

Now, running npm start will run the client, as well as the backend server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.128.129