Skip to content
Latchkey

npm run: Execute package.json Scripts

npm run is how CI invokes your build, test, and lint scripts.

Scripts in package.json are the contract between your repo and CI. npm run executes them with the local node_modules/.bin on PATH.

Common usage

  • npm run <script> - run a named script
  • npm run <script> -- <args> - forward args
  • npm run - list available scripts
  • --if-present - do not fail if missing

Example in CI

Forward a flag to the underlying tool.

shell
npm run test -- --coverage

In CI

A non-zero script exit fails the job. missing script errors mean the script name is not in package.json. Use --if-present for optional steps across repos.

Key takeaways

  • Use -- to forward args to the tool.
  • Non-zero exit fails the CI job.
  • --if-present skips missing scripts safely.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →