I ran npm ls on a Next.js project and saw more than 800 transitive packages in the tree. That number surprised me, but package count alone does not say how risky an application is. Some packages are only used during development or build; others are included in production. The useful question is what the project installs, runs, and exposes to each dependency.
Where dependency risk comes from
Packages can be compromised, abandoned, or confused with similarly named packages. Install-time lifecycle scripts can execute code during installation, and code that runs inside an application can access what that process can access. The exact exposure depends on when the package runs, the permissions around the build or service, and what credentials are present.
Private package names also need deliberate registry configuration. Dependency-confusion attacks exploit ambiguous package sources or resolution rules; using a private scope and explicit registry settings helps avoid accidentally resolving an internal name from an unintended registry.
What I check
Keep and review the lockfile. A package manifest describes acceptable version ranges. A lockfile records a resolved dependency tree, and npm uses it during reproducible installs when it matches the manifest. Updating dependencies or regenerating the lockfile can change that tree, so review those changes as code. npm documents how npm install uses package manifests and lockfiles.
Know which packages execute scripts. npm packages can define lifecycle scripts, but not every dependency runs an install script. Review unexpected scripts and use --ignore-scripts where the project can work without them; some packages rely on scripts to build or download required files, so check the effect before applying it broadly. See npm lifecycle scripts.
Add dependencies deliberately. Check whether a package is maintained, whether it does the job you need, and whether it introduces transitive packages or install behavior that matters to your project. Writing a small utility yourself is not automatically safer; your code also needs review and maintenance.
Use audits as input, not a pass/fail badge. Review advisories for affected versions, reachable code paths, available fixes, and the risk of upgrading. A clean audit does not prove a package is trustworthy or that your application is secure.
Reduce exposure at build and runtime
Avoid placing unnecessary credentials in build environments. Give CI jobs and production services only the permissions they need, and separate development dependencies from production where your deployment process supports it. Keep dependency updates visible in version control and make a plan to review important changes.
A large tree deserves attention, but the count is only a starting point. I focus on which code can execute, what it can access, and how changes to the resolved tree are reviewed.