Audit and Fix Dependency Vulnerabilities
Scan your project for known security vulnerabilities in dependencies, understand severity levels, and apply fixes safely.
Prerequisites
- -Node.js and npm installed
- -A project with package-lock.json
Steps
Run a security audit
Scan all dependencies for known vulnerabilities.
View detailed audit report as JSON
Get machine-readable output for CI integration or detailed analysis.
Pipe to jq for filtering: 'npm audit --json | jq '.vulnerabilities | to_entries[] | select(.value.severity=="critical")'
Auto-fix compatible vulnerabilities
Automatically update packages to patched versions within semver range.
npm audit fix only updates within the current semver range. It will not make breaking changes to your dependency tree.
Force-fix with major version updates
Apply fixes that may include breaking semver changes.
Always use --dry-run first to review changes. Force-fixing can introduce breaking changes that require code updates.
Check audit in CI with exit codes
Fail CI builds when critical or high vulnerabilities are found.
Use --audit-level to set the minimum severity that causes a non-zero exit code: info, low, moderate, high, critical.
Full Script
FAQ
Discussion
Loading comments...