Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

npm install does more than place packages in node_modules: it resolves a dependency tree, follows the project’s lockfile when that lockfile fits the declared package ranges, and may run package lifecycle scripts. Those are separate behaviors. A lockfile helps reproduce dependency versions; it does not prevent installed code from running.

What npm install does

In a project, npm install reads the dependency declarations in package.json, resolves a tree of packages, and installs that tree. The details depend on the project’s lockfile and configuration. npm’s install documentation describes these rules; the available settings and defaults can vary by npm CLI version.

It resolves dependencies, not just direct packages

A dependency can itself require other packages. npm resolves those relationships into an installable tree, so installing one direct dependency can also add or update transitive dependencies. The resulting tree is reflected in node_modules and, where applicable, the lockfile.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A compatible lockfile pins the resolved versions

When package-lock.json exists and its recorded versions satisfy the ranges declared in package.json, npm install uses the versions in the lockfile. This makes the resolved tree more repeatable than resolving every range afresh.

If the manifest and lockfile no longer align—for example, a declared range changes—npm can resolve a new tree that satisfies the manifest and update the lockfile. Review resulting lockfile changes as dependency changes, rather than assuming that running install can never change versions.

Why a lockfile does not control what code runs

A lockfile records dependency-resolution information. It does not establish that a package is trustworthy, nor does it disable the package’s install-time behavior. Version reproducibility and execution control are different safeguards: the first narrows which versions are installed; the second governs whether their scripts may run.

When installation can run scripts

Packages can define lifecycle events such as preinstall, install, and postinstall. npm also documents prepare behavior for non-registry dependencies. The root project can have lifecycle scripts too. The npm scripts documentation describes the events and when they apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This does not mean every package has an install script, or that every install runs every lifecycle event. But when an applicable script is run, installation can execute code from the project or a dependency. Such scripts may build native bindings or generate assets; their presence is not, by itself, evidence of malicious intent. For an unfamiliar package, inspect its scripts and available provenance information before deciding whether to allow its install behavior.

Ways to control install-time scripts

Approach Effect Trade-off
ignore-scripts Suppresses scripts specified in package manifests during commands such as installation. Packages that need install-time builds or generated files may not work as expected.
allow-scripts policy Allows install-time scripts for packages identified by the policy. The policy must be reviewed and maintained as dependencies change.
strict-allow-scripts Can make installs fail when script-bearing packages are not covered by the policy. New or unreviewed dependencies can interrupt an install until the policy is updated.

npm’s install documentation says of ignore-scripts: “If true, npm does not run scripts specified in package.json files.” It also clarifies that an explicit command intended to run a script, such as npm test or npm run, still runs that intended script; with the setting enabled, npm skips the associated pre- and post-scripts. Check the current install documentation for the exact behavior supported by your npm CLI.

For finer control, npm documents allow-scripts and strict-allow-scripts. Their availability and configuration are version-sensitive, so confirm the documentation for the CLI version the project supports before adopting a policy. npm describes dangerously-allow-all-scripts as a migration escape hatch that bypasses the policy and strongly discourages its use; it is not a routine hardening choice.

Choosing settings for local work and CI

Local development

Keep the project’s lockfile under version control and review unexpected lockfile changes after installing. If you are evaluating an unfamiliar dependency, inspect its package scripts and provenance signals before allowing its install behavior. Blanket script suppression can be a useful check, but validate that the project still builds and runs without scripts before relying on it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Continuous integration

For a CI workflow that must install exactly the committed dependency tree, consider npm ci. npm documents that it validates the lockfile against package.json; its scripts documentation says the root preinstall runs after this validation. That validation improves consistency, but it is not a policy that prevents lifecycle scripts from executing. Decide separately whether the build requires those scripts and whether to suppress or selectively allow them. See npm ci documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What lockfile checks, audits, and signatures can tell you

Signal or control What it addresses What it does not establish
Lockfile use or npm ci validation Helps keep dependency resolution aligned with the recorded tree; npm ci checks that the lockfile matches the manifest. That package code is benign or that lifecycle scripts cannot run.
npm audit Reports known vulnerability information for dependencies. That packages have no unknown vulnerabilities or unsafe install behavior.
npm audit signatures Can verify registry signatures and provenance attestations where supported. A complete safety guarantee for package code or its effects during installation.

These checks answer different questions and are best treated as complementary signals, not as certification that an install is safe. npm’s audit documentation also explains audit behavior and registry configuration; audit submission may go to the default or configured scoped registries when enabled. Check that documentation and your registry settings if the destination or data submitted matters to your environment.

Check version-specific behavior before setting policy

The npm documentation available for this article identifies CLI 12.1.0 as the latest version at crawl time, and npm’s v11 install documentation also describes the allow-scripts family. Do not assume a machine or project uses either version: check the installed CLI with npm --version, then use the matching official documentation for supported options and configuration. Compare the current install documentation with the npm CLI v11 install documentation when maintaining projects across CLI versions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.