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

1

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.