Npm
Introduction
npm (originally short for Node Package Manager) is a package manager for the JavaScript programming language managed by npm, Inc. It is the default package manager for the Node.js runtime environment. npm consists of a command-line client, also called npm, and an online database of public and paid-for private packages, called the npm registry. The registry is accessed via the client, and the available packages can be browsed and searched via the npm website.
History
npm was created by Isaac Z. Schlueter and first released in 2010. Its development was sponsored by the hosting company Joyent, which employed Schlueter at the time. The project was designed to solve the problem of sharing reusable JavaScript code, especially for server-side Node.js development. In 2014, npm, Inc. was founded as a separate company to manage both the open-source client and the registry. The npm registry grew rapidly, becoming the largest package ecosystem for any programming language. In 2020, npm was acquired by GitHub, a subsidiary of Microsoft. The acquisition ensured continued development and integration with GitHub’s platform.
Features
- Package installation – npm allows developers to install packages locally in a project's `node_modules` directory or globally on the system.
- Dependency management – Packages list their own dependencies in a `package.json` file, which npm uses to resolve and install the full dependency tree.
- Versioning – npm uses Semantic Versioning (semver) to manage package versions, enabling developers to specify version ranges.
- Scripts – The `package.json` file supports custom scripts that can be run via `npm run <script>`.
- Private packages – npm offers private package hosting for organizations, with access control and team management.
- Security audits – The `npm audit` command checks installed packages for known vulnerabilities.
- Workspaces – Support for managing multiple packages in a single repository (monorepo).
Usage
The npm client is typically invoked from the command line. Common commands include:
- `npm init` – Creates a new `package.json` file.
- `npm install <package>` – Installs a package and adds it to dependencies.
- `npm publish` – Publishes a package to the registry.
- `npm update` – Updates packages to their latest allowed versions.
- `npm run` – Executes scripts defined in `package.json`.
The registry hosts over two million packages (as of the mid-2020s), making npm one of the largest software registries in existence. The client is open-source software released under the Artistic License 2.0.