npm (Node Package Manager) is the default package manager for Node.js, providing a command-line interface for installing, sharing, and managing project dependencies. It interacts with the vast npm public registry, which hosts millions of JavaScript packages. The current stable version is 11.12.1, with frequent releases that include bug fixes, performance improvements, and new features. Its key differentiators include its ubiquitous adoption as the standard for Node.js development, its comprehensive registry, and integrated tools for tasks like package auditing, publishing, and script execution. npm is an indispensable tool for nearly all JavaScript and TypeScript projects utilizing the Node.js runtime.
npm install npmVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic 'npm' command-line usage for initializing a project, installing local and global dependencies, and running package.json scripts.
Always check the 'engines' field in `npm`'s package.json or the official documentation for compatible Node.js versions. Use a Node Version Manager (like nvm, fnm, or volta) to easily switch between Node.js versions.
Resolve dependency conflicts by aligning package versions. Use `npm install --legacy-peer-deps` as a temporary workaround (not recommended for production). For permanent fixes, consider `npm overrides` (npm 8+) to force specific transitive dependency versions.
After resolving `package.json` conflicts, run `npm install` (or `npm install --package-lock-only`) to automatically re-resolve `package-lock.json`. Consider using `npm ci` in CI/CD environments for reproducible builds that strictly adhere to the lockfile. Ensure all team members use consistent Node.js and npm versions.
Prefer using `child_process.spawn` or `exec` to run npm commands as a CLI. For specific programmatic needs, use the dedicated `libnpm*` packages (e.g., `libnpminstall`, `libnpmpublish`, `@npmcli/arborist`) which provide stable, modular APIs for npm's underlying functionalities.
Install Node.js from the official website or via a Node Version Manager (nvm, fnm, volta). Verify Node.js and npm are installed by running `node -v` and `npm -v`. Check and update your system's PATH variable if necessary.
The recommended fix is to use a Node Version Manager (like nvm) which manages Node.js and npm installations in user-writable directories. Alternatively, change npm's default global installation directory to a user-owned location, or fix existing directory permissions (use `sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}` with caution). Never use `sudo npm install -g` as a routine fix.Inspect the detailed error output to identify conflicting packages. Try `npm install --legacy-peer-deps` (for quick local fixes, not recommended for CI/production). Adjust versions in your `package.json` to satisfy requirements, or use the `overrides` field in `package.json` (npm 8+) to explicitly define transitive dependency versions.