ryoakg
3/31/2017 - 3:24 AM

how to use npm scripts

how to use npm scripts

{
  "name": "some-project",
  "version": "1.0.0",
  "scripts": {
    "foo": "echo foo",
    "multiple-commands": "echo 1; echo 2",
    "using-pipe": "cat /etc/passwd | grep home",

    "parent": "npm run child",
    "prechild": "echo <PRE>CHILD",
    "child": "echo CHILD",
    "postchild": "echo <post>CHILD",

    "using-node": "node -e \"console.log('from NodeJs')\"",
    "complex-command": "./bin/complex-command"
  }
}

setup

Write a package.json or run npm init to generate it and fill its scripts property.

run a script

npm run foo
npm run bar

passing parameters to a script

npm run foo -- abc 123

further info