This procedure walks you through installing an npm package into a project.
🧰 Prerequisites
Set up everything below before continuing. The steps assume it is already in place.
- Node.js installed
- A project folder open in the terminal
📋 Steps
-
Open the terminal in the project folder.
-
Run the install command, replacing
package-namewith the name of the package to install:npm install package-name -
Wait for the command to finish. npm downloads the package and adds it to the project.
🎯 Expected Outcome
After the command finishes, the project folder contains two new entries:
project/
node_modules/ the installed package and anything it depends on
package.json records the package as a dependency of the projectThe node_modules folder holds the package code. The package.json file lists the package under its dependencies, so the project has a record of what it needs.
⚠️ Mistakes
Running the command outside the project folder
npm install installs into the folder the terminal is currently in. If the terminal is in the wrong folder, the package installs in the wrong place. Make sure the terminal is in the project folder before running the command.
Misspelling the package name
npm looks up the exact name given. A misspelled name either fails to find the package or installs a different one. Copy the name from the package’s official page to be sure it is correct.
Expecting the package name to be optional
npm install with no name does not install a specific package. It reads existing dependencies from package.json instead. To install a specific package, always give its name: npm install package-name.
📚 Resources
- npm install (external link), official docs
- An introduction to npm (external link), Node.js