3

I'm trying to write an example of running npm tasks in parallel. We are supposed to be able to do this with "&" for parallel and "&&" for series.

{
  "name": "npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "console": "node ./npm-scripts/console.js",
    "task1": "node ./npm-scripts/task1.js",
    "task2": "node ./npm-scripts/task2.js",
    "task3": "node ./npm-scripts/task3.js",
    "parallel": "npm run task1 & npm run task2 & npm run task3",
    "series": "npm run task1 && npm run task2 && npm run task3"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "date-and-time": "^0.3.0"
  }
}

This doesn't seem to actually work.

Here is where my code is. I'm using Visual Studio 2015 but if you know NPM then you can just use the command line.

my github parallel and series examples

Thanks in advance for any help.

Bob

Sven
  • 5,155
  • 29
  • 53
user3448990
  • 323
  • 6
  • 15
  • Possible duplicate of [How can I run multiple NPM scripts in parallel?](http://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel) – James Choi Feb 24 '16 at 04:56

1 Answers1

2

On Windows, we cannot use & to run tasks in parallel.

npm-run-all is useful in this case, IMO.

{
    "name": "npm",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "console": "node ./npm-scripts/console.js",
        "task1": "node ./npm-scripts/task1.js",
        "task2": "node ./npm-scripts/task2.js",
        "task3": "node ./npm-scripts/task3.js",
        "parallel": "npm-run-all --parallel task1 task2 task3",
        "series": "npm-run-all task1 task2 task3"
    },
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "date-and-time": "^0.3.0",
        "npm-run-all": "^1.5.1"
    }
}

We can use glob-like pattern to specify tasks:

        "parallel": "npm-run-all --parallel task{1,2,3}",
        "series": "npm-run-all task{1,2,3}"

Other solutions:

mysticatea
  • 1,917
  • 1
  • 12
  • 12