NPM - Script


npm scripts are command line that are specified in the script element of package.json.



Command line

To run a script, you would execute the following npm command

yarn scriptName
# or
npm run scriptName


To run the script sequentially on all platform.

Example with the release script:

"scripts": {
    "build": "cross-env NODE_ENV=production webpack --mode 'production'",
    "test": "jest",
    "publish": "npm publish",
    "release": "npm-run-all test build publish",


From the VsCode IDE in a VsCode - Task (tasks.json)

    // See 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
            "type": "npm",
            "script": "test",
            "group": {
                "kind": "build",
                "isDefault": true

Shortcut (Alias)

  • npm test is a shortcut for npm run test
  • npm start is a shortcut for npm run start

Search path

Within scripts you can reference locally installed npm packages by name instead of writing out the entire path. This convention is the standard in most npm-based projects and allows for instance to directly call a package. Example:

  • myApp,
  • instead of ./node_modules/.bin/myApp

Documentation / Reference

Powered by ComboStrap