Skip to main content

How do you install a package?

A package is installed with the npm install command (or the shorthand npm i).


Installing dependencies in a project

  1. A regular dependency (goes into dependencies):
bash
npm install <package-name>
  1. A development-only dependency (in devDependencies):
bash
npm install <package-name> --save-dev

Installing globally (to use as a CLI)

bash
npm install -g <package-name>

Summary

To install a package, you use the npm install command with the package name. Depending on the flag, the package ends up in regular dependencies, in dev dependencies, or gets installed globally.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.