7

I have built an app using Vue.js and express.js. Currently I have to open two terminal windows and run npm run serve in one and npm start in the other. I want to make the server run after the Vue.js app builds in the same terminal. I read on this article that I can get both scripts to run by chaining the two package.json scripts together, but for the life of me can't figure out how. My project is structured as such:

├── project
├── _frontend
|   ├── package.json
├── backend
|   ├── package.json

I have tried the following ways:

1st try - "serve": "vue-cli-service serve && (cd ../server && npm start)"
2nd try - "serve": "vue-cli-service serve && (cd ../server && npm run start)"
3rd try - "serve": "vue-cli-service serve && (cd ../server) && npm start"

The Vue.js app builds and runs just fine but the server does not start. I tried doing the reverse on the server package.json as well and the server starts but the app does not build. Is this something I can not accomplish due to the folder setup or what am I doing wrong?

Andrew Vasylchuk
  • 4,671
  • 2
  • 12
  • 30
jaronow
  • 113
  • 8
  • 1
    Possible duplicate of https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel – Estus Flask Aug 18 '19 at 06:47

1 Answers1

7

&& executes commands in series. vue-cli-service serve && cd ../server && npm start won't work as expected because the script stops at vue-cli-service serve until the server is shut down.

For cross-platform script, concurrently or other similar packages can be used to execute commands in parallel:

"serve": "vue-cli-service serve",
"start": "concurrently \"npm run serve\" \"cd ../server && npm start\""
Estus Flask
  • 206,104
  • 70
  • 425
  • 565