npm install
Packages and runtimes
Usage
npm install [<package>] [-D|-g]Downloads the dependencies package.json asks for into node_modules and updates package-lock.json; since npm 7 peer dependencies are installed too, and --production was replaced by --omit=dev.
Common flags
| Flag | Meaning |
|---|---|
| -D | save as a devDependency |
| -g | install globally, onto PATH |
| -E | save the exact version, without a caret |
| --omit=dev | skip devDependencies; replaces the old --production |
| --legacy-peer-deps | ignore peer conflicts the way npm 6 did |
| --ignore-scripts | do not run install scripts |
| --force | overwrite cache and conflict checks |
Examples
npm installinstalls what package.json asks for and updates package-lock.json
npm install -D vitestadds a dev-only dependency
npm install react@18.3.1installs one exact version and records it
The question is always what goes where: inside this project, or on the whole machine.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does npm install do?
Downloads the dependencies package.json asks for into node_modules and updates package-lock.json; since npm 7 peer dependencies are installed too, and --production was replaced by --omit=dev.
Q. How do I type it?
npm install [<package>] [-D|-g] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man npm. This command sits under Packages and runtimes.
Related commands
man page: man npm-install