5

I am going to build my boilerplate for React and node, the root folder structure is look like this

    - (root level)
    - client - src
             - public
             - package.json
             - ... 

    - package.json
    - server.js
    - node_modules

In my package.json of root folder, I have some code like:

 "start": " nodemon ./server.js | react-scripts start ./client"

When I run npm start, only the react app is build and run, the node app doesn't run. Any tips for how to just run npm start and both React and node app run?

By the way, I have set "proxy": "http://localhost:5000/" in the client's package.json. The server.js has code like

const port = process.env.PORT || 5000;

// console.log that your server is up and running
app.listen(port, () => console.log(`Listening on port ${port}`));

Thank you.


Solution:

Thanks so much for rodrigoap replies.

I use the concurrently package to solve my problem.

My package.json in my root folder look like this and work:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "concurrently \"cd client && npm run start\" \"npm run start\"",
    "start": "nodemon ./server.js"
  },
Terence Zhong
  • 181
  • 4
  • 13
  • Would any of these solutions work? https://itnext.io/4-solutions-to-run-multiple-node-js-or-npm-commands-simultaneously-9edaa6215a93 – rodrigoap Aug 11 '19 at 22:49
  • 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) – rodrigoap Aug 11 '19 at 22:50
  • 1
    your solutions is really helpful, I will try to fix it by reading them first and will update my solutions later, thanks mate – Terence Zhong Aug 11 '19 at 22:57

1 Answers1

0

I found 2 ways to do it

1 by command

"scripts": {
    "start": "react-scripts start",
    "dev": "(cd server && npm run start) & npm run start"
  }

2 by npm package

  • concurrently npm
  • npm-run-all npm
bhavesh
  • 453
  • 3
  • 11