Safeguard
Developer Tools•

How do I scan npm dependencies for vulnerabilities?

Run npm audit in a project that has a package-lock.json. It sends your dependency list to the registry and returns known vulnerabilities and fixes.

Safeguard Security Team
4 min read

Run npm audit in your project folder. It submits a description of your configured dependencies to the registry and returns known vulnerabilities with the remediation it calculates. By default it needs a package-lock.json, and it exits with a non-zero code when it finds something, which makes it usable in CI.

What the command does

According to the npm documentation, npm audit sends the dependency description to your default registry and asks for a report. If it finds issues, it works out the impact and suggests a fix. The report covers the whole tree, not just the packages in your package.json.

Steps

  1. Make sure package-lock.json exists and is committed.
  2. Run the audit from the project root.
  3. Read the report, starting with high and critical findings in direct dependencies.
  4. Re-run after you update packages.
  5. Add the command to CI with a failure threshold.
npm audit
npm audit --json
npm audit --audit-level=high

The audit level option sets the lowest severity that causes a non-zero exit. The npm docs are clear that it does not filter the report. It changes just the failure threshold.

Useful variations

NeedApproach
Machine readable outputAdd the JSON option
Fail CI only on serious findingsSet the audit level to high or critical
Skip dev toolingOmit the dev dependency type
Verify package integrityRun npm audit signatures

The signatures command verifies registry signatures of downloaded packages, and provenance attestations too. That is a different question from known vulnerabilities, so run both.

Limits to know

  • The audit reports what the registry knows. A new advisory is not visible until it is published.
  • Without a lockfile you can bypass the requirement with a flag, but results may differ between runs.
  • A finding in a package does not prove your code reaches the flawed function.

How to read the result

Each finding names the vulnerable package, the range of affected versions, and a recommended fix when one exists. Look at the dependency path to see which of your direct packages brings it in. A finding on a direct dependency is usually a one line change. A finding several levels down may need a parent upgrade, or an override, and the report will say when the fix needs manual review.

Keep a copy of the JSON output from each run. Comparing two runs shows what is new since the last release, which is more useful than a single long list.

A sensible CI setup

  1. Install with the lockfile, so the tree matches what you ship.
  2. Run the audit with a high severity threshold and fail the job on a non-zero exit.
  3. Run a second, broader audit on a schedule and send the output to the owning team.
  4. Review the threshold each quarter and lower it as the backlog shrinks.

Try it yourself

Click through it at your own pace, or open it full screen.

Open a finding and compare its severity with the fix version shown.

Quick check

Does npm audit change my files?

No. Plain npm audit just reports. The fix variant modifies your tree, and that is covered in a separate post.

Should CI fail on every finding?

Usually not at first. Start with high and critical, then tighten as the backlog shrinks.

Safeguard adds reachability analysis and policy gates on top of dependency findings, and you can run a free scan without setup.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.