Sometimes we need to run a fake API with JSON-Server and SPA at the same time.
We need to run each command, one for our spa vue serve or ng serve and the other for json-server json-server /db.json
One solution is with concatenating each command using &&, but if tomorrow we need to start another program, the line will look like:
npm run lint && npm run build && npm run API && npm run wherever thing :P
Then I found npm-run-all is a node package. It allows us to run all scripts defined in npm in sequential or parallel, each one in parallel.
First install npm-run-all.
npm install -g npm-run-all
The define a new option into our script area, like all, and call the npm-run-all with the type of execution --parallel or sequentially (by default) and scripts names.
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"api": "json-server src/db.json",
"all": "npm-run-all --parallel serve api"
},
Happy NPM!
Photo by Matúš Kovačovský on Unsplash