# npm Scripts Cheat Sheet: Commands, Lifecycle & CI Flags

> An npm scripts cheat sheet - run, ci, install, lifecycle hooks, pre/post scripts, and the npm flags you use in CI pipelines.

Source: https://latchkey.dev/learn/cheat-sheets/npm-scripts-cheat-sheet  
Updated: 2026-06-26

npm commands, lifecycle scripts, and the CI-friendly flags in one reference.

Install, run, and version with npm - plus the pre/post script lifecycle.

## Core commands

| Command | Does |
| --- | --- |
| npm ci | Clean, lockfile-exact install (CI) |
| npm install | Install + update lockfile |
| npm run <script> | Run a package.json script |
| npm test | Shorthand for run test |
| npm exec / npx pkg | Run a binary without installing |
| npm outdated | List stale deps |

## Lifecycle hooks

| Script | Runs |
| --- | --- |
| pre<name> | Before <name> |
| post<name> | After <name> |
| prepare | After install, before publish |
| prepublishOnly | Before publish only |

## Useful flags

| Flag | Effect |
| --- | --- |
| --workspaces | Run across all workspaces |
| -w <pkg> | Target one workspace |
| --if-present | Skip if script missing |
| --silent | Quiet output |

## Example

```package.json
{
  "scripts": {
    "build": "tsc && vite build",
    "prebuild": "npm run lint",
    "test": "vitest run",
    "ci": "npm run build && npm test"
  }
}
```

## FAQ

### npm Scripts Cheat Sheet: Commands, Lifecycle & CI Flags?

Install, run, and version with npm - plus the pre/post script lifecycle.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
