switch·Esc back

npm

You might say

AI told me to install dependencies, and one command downloaded a ton of stuff. What's going on?

Install JavaScript packages and run project scriptsnpm is a package manager and command runner for JavaScript projects. package.json records dependencies and named scripts, while the lockfile keeps installed versions reproducible. Install packages intentionally and review scripts before running code from an unfamiliar project.
Know first
package.json · Manifest "react": "^19.0.0" "vite": "^6.0.0" "scripts": dev / build
npm
install
node_modules · Dependency directory 📦 react 📦 vite 📦…42 packages in total

When to use it

  • Install declared dependencies
  • Add a library to a project
  • Run scripts such as dev, test, and build
  • Keep dependency versions reproducible with a lockfile

When NOT to use it

  • Commit the node_modules directory
  • Delete the lockfile whenever versions conflict
  • Install a package before checking whether the platform already provides the feature
  • Run an unfamiliar package script without reading it
Anatomy
{   "name": "my-first-page",   "dependencies": { "react": "^19.0.0" },   "scripts": { "dev": "vite", "build": "vite build" } }
The name and version of the project, used when publishing and sharing
Which packages and versions are installed; install and move the goods accordingly.
npm run dev runs the command written here
Variants
install
npm install
Install new packages, or rebuild node_modules
run
npm run dev
Execute shortcut commands in scripts
uninstall
npm uninstall lodash
The bag is no longer needed, so cross it off the list.
lockfile
package-lock.json
Team unified version, don’t change it manually
Typical use cases
Project setup
package.json
{
  "name": "my-first-page",
  "dependencies": { "react": "^19.0.0" },
  "scripts": { "dev": "vite", "build": "vite build" }
}
Add dependency
zsh — my-first-page
$ npm install ⸨████████░░⸩ reify: react added 42 packages in 6s Dependencies will be installed to node_modules according to package.json and lock files
Development server
my-first-page
📁 node_modules380 MB · ⚠ Automatically generated, do not move
📄 package.jsonEvents
📄 .gitignoreIt says node_modules and .env
Production build
zsh — my-first-page
$ npm run dev > my-first-page@0.1.0 dev ✓ Ready in 1.2s → http://localhost:3000 Shortcut commands in scripts, one for each string
Further reading