npm scripts

By: Colten Rouska

(12/4/15)

What is npm?

What are npm scripts?

npm run-script <command> [-- <args>]
npm run <command> [-- <args>]

What do they do?

// package.json

{
  "name": "my-test-scripts",
  "scripts": {
    "test": "mocha tests",
    "say-hello": "echo \"Hello!\"",
    "test:watch": "npm test -- -w"
  }
}

Examples

Best Practices

  • Only exit with a non exit code if it is meant to stop the process of installing packages
  • Use the npm tool don't recreate what npm does using the scripts sections
  • Don't prefix script commands with sudo
  • Don't use install. Use .gyp file compilation and prepublish for anything else.

npm scripts

By Colten Rouska (Rizowski)

npm scripts

A short description for what npm scripts are for and how they should be used. Some examples are going to be presented from this project: https://github.com/rizowski/npm-scripts-example

  • 823