Use pattern to shorten command of Concurrently

Sometimes, we want to run some scripts in a parallel manner. Concurrently package helps you just do that.

npm install concurrently
  • I want to add all scripts under names starting with start, so I don't have to type names in concurrently script.

    • I don't want to write concurrently "command1 arg" "command2 arg"

    • I want to write concurrently npm:start:*

  • Here to demonstrate, I am using Vite for frontend and json-server for storing the data.

  • Problem is, I want to run them together with one simple command.

  • npm start is one of the command that doesn't require to write run like npm run doSomething.

  • So I will use npm start to start multiple commands.

  • Command for Vite is npx vite

  • Command for json-server is npx json-server -w db.json

  • In package.json, I will cobine them like this ( just an example ... )

"scripts": {
    "start:frontend": "vite",
    "start:backend": "json-server -w db.json",
    "start": "concurrently npm:start:*"
},
"devDependencies": {
    "vite": "^4.1.0",
},
 "dependencies": {
    "concurrently": "^7.6.0",
    "json-server": "^0.17.2"
}