search

Home  >  Q&A  >  body text

How to run multiple npm scripts in parallel?

<p>In my <code>package.json</code> I have these two scripts: </p> <pre class="brush:php;toolbar:false;">"scripts": { "start-watch": "nodemon run-babel index.js", "wp-server": "webpack-dev-server", }</pre> <p>Every time I start developing in Node.js, I have to run these two scripts <strong>in parallel</strong> My first thought was to add a third script like this: </p> <pre class="brush:php;toolbar:false;">"dev": "npm run start-watch && npm run wp-server"</pre> <p>...but this will wait for <code>start-watch</code> to complete before running <code>wp-server</code>. </p> <p><strong>How can I run these commands in parallel? </strong>Keep in mind that I need to see the <code>output</code> of these commands. Also, if your solution involves build tools, I'd rather use <code>gulp</code> than <code>grunt</code> since I'm already using it in another project. </p>
P粉807239416P粉807239416502 days ago550

reply all(2)I'll reply

  • P粉026665919

    P粉0266659192023-08-24 10:31:34

    If you are using a UNIX-like environment, just use & as the delimiter:

    "dev": "npm run start-watch & npm run wp-server"

    Otherwise, if you are interested in a cross-platform solution, you can use the npm-run-all module:

    "dev": "npm-run-all --parallel start-watch wp-server"

    reply
    0
  • P粉143640496

    P粉1436404962023-08-24 00:58:21

    Use a package named Concurrency.

    npm i concurrently --save-dev

    Then set up your npm run dev task as follows:

    "dev": "concurrently --kill-others \"npm run start-watch\" \"npm run wp-server\""

    reply
    0
  • Cancelreply