1

I've setup json-server and runs successfully on port-3000 then run npm start it runs on other port 3001.

But I want to run both concurrently. I tried with Concurrently but didn't work.

When I execute this command :

$ concurrently "npm start" "json-server --watch ./topPanelData.json"

Error message:

Error message

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
Harshal Wani
  • 2,249
  • 2
  • 26
  • 41
  • Possible duplicate of [How can I run multiple npm scripts in parallel?](https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel) – Dinesh Pandiyan Dec 22 '18 at 02:13

3 Answers3

4

Resolved issue with these steps:

  1. Create json-server.json with the following key to run a server on a different port.

    { "port": 4000 }

  2. Update start script in package.json

    "start": "concurrently \"react-scripts start\" \"json-server ./topPanelData.json\""

  3. simply run $ npm start It'll concurrently execute both on the different port

    json-server: http://localhost:4000/topPanelData

    React app: http://localhost:3000/

Harshal Wani
  • 2,249
  • 2
  • 26
  • 41
  • 1
    just remember people to download concurrently and save it as a dev dependency: https://www.npmjs.com/package/concurrently – Leonardo Rick Jul 24 '22 at 21:11
0

You can kill the process running in port 3000 with

kill $(lsof -t -i:3000)

Where

lsof -t -i:3000

finds the process running on port 3000 and kill kills that process

If you're only getting this error on using concurrently, that means it's trying to run both processes in port 3000

Try changing your start script in package.json

"start": "export PORT=3006 react-scripts start"

With some experimentation, you'll be able to figure it out.

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
0

Just create an .env file in your porject directory, parallel to .json file and add below line .

PORT=3001

This solution worked for me .