# npm audit

> The `npm audit` command checks project dependencies for known security vulnerabilities.

## How do I fix vulnerabilities found by npm audit?

The command that analyzes installed dependencies and reports known vulnerabilities with their severity. Running `npm audit fix` automatically updates vulnerable packages to compatible fixed versions.

- Topic: npm Commands
- Type: command

## Example

Wrong:

```bash
npm audit fix --force
```

Right:

```bash
npm audit --omit=dev
npm audit fix
git add package-lock.json
```

Plain `npm audit fix` stays within semver ranges, while `--force` can install breaking majors without review.

## Common mistakes

- Running `npm audit fix --force` and getting breaking major upgrades of dependencies.
- Panicking over warnings in dev-only tools that never ship to users.

## Key points

- Fixes are applied with `npm audit fix`, and `--force` is used only after checking the major upgrades it installs.
- Production risk is checked with `npm audit --omit=dev`.
- The updated lock file is committed together with the fix.

## Interview questions

### How do I fix a vulnerable transitive dependency?

Update the parent package first. If no fix exists, pin a safe version with the `overrides` field in `package.json`.

### Can npm audit fail a CI build?

Yes. It exits with a non-zero code when it finds issues, and `--audit-level=high` sets the minimum severity that fails.

### Is every npm audit warning a real risk?

No. Many affect dev tools or code paths you never use, so check whether the vulnerable code runs in production.

## Related cards

- [`npm update <package>`](https://wonderium.dev/processes/npm-update.md)
- [npm outdated](https://wonderium.dev/processes/npm-outdated.md)
- [Lock file](https://wonderium.dev/processes/lock-file.md)
- [Slopsquatting](https://wonderium.dev/ai/slopsquatting.md)
- [npm ci](https://wonderium.dev/processes/npm-ci.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/npm-audit
- Last updated: 2026-11-25
