Skip to main content
The npm module manages Node.js packages using npm (Node Package Manager).

Functions

packages

Install, remove, or update npm packages.
str | list[str]
List of packages to ensure.
bool
default:true
Whether the packages should be present.
bool
default:false
Whether to upgrade packages without a specified version.
str
Directory to manage packages for. Defaults to global installation.
Package versions can be pinned like npm: <pkg>@<version>

Examples

Common Use Cases

Express.js Application Setup

React Application

Global Development Tools

Install from package.json

Build Tools

Testing Framework

npm-Specific Tips

Global packages (no directory parameter):
  • Installed system-wide
  • Typically CLI tools
  • Use npm install -g
Local packages (with directory parameter):
  • Installed in project’s node_modules
  • Project dependencies
  • Use npm install in directory
For full project setups, use package.json:
Update packages to latest versions:
Install scoped packages (organization packages):
Perform a clean install (removes node_modules):
Install from private npm registries:

Best Practices

Always commit and deploy package-lock.json for reproducible builds:

Important Notes

When no directory is specified, packages are installed globally using npm install -g.
Global npm installations may require sudo/administrator privileges depending on Node.js installation.
For production deployments, use npm ci instead of npm install for faster, more reliable builds.