Skip to main content

How does a local install differ from a global one?

A local install puts a package inside a specific project, in the node_modules folder next to package.json.

A global install puts a package at the system level, so it is available from any project as a CLI tool.


Local install

bash
npm install <package>
  • The package is stored in ./node_modules
  • An entry is added to dependencies or devDependencies
  • Available only inside this project
  • Used for libraries the application needs at runtime or build time (React, Webpack, Axios, etc.)

Global install

bash
npm install -g <package>
  • The package is installed into npm's system directory
  • Not available as a project dependency
  • Can be invoked as a terminal command from any directory
  • Usually used for CLI utilities (for example: nodemon, npm-check, create-react-app)

Comparison

TraitLocalGlobal
Where it installsInto the project (node_modules)Into the system
VisibilityOnly in the projectFor all projects
Entry in package.jsonYesNo
What it suitsProject librariesCLI tools

Short summary: a local install is for project dependencies, a global install is for tools you need to run from anywhere on the system.

Short Answer

Interview ready
Premium

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