Convert Figma logo to code with AI

npm logocli

the package manager for JavaScript

8,333
3,061
8,333
673

Top Related Projects

41,396

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry

29,125

Fast, disk space efficient package manager

73,021

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

10,872

Volta: JS Toolchains as Code. ⚡

78,700

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Quick Overview

npm/cli is the command-line interface for the Node Package Manager (npm), which is the default package manager for Node.js. It allows developers to install, manage, and publish JavaScript packages, as well as run scripts and manage project dependencies.

Pros

  • Extensive ecosystem with a vast number of packages available
  • Built-in security features, including vulnerability checks
  • Seamless integration with Node.js projects
  • Regular updates and active maintenance

Cons

  • Can be slow for large projects with many dependencies
  • Occasional issues with package versioning and conflicts
  • Complex dependency trees can lead to bloated node_modules folders
  • Learning curve for advanced features and configurations

Code Examples

  1. Installing a package:
npm install lodash

This command installs the lodash package and adds it to the project's dependencies.

  1. Running a script defined in package.json:
npm run start

This command runs the "start" script defined in the project's package.json file.

  1. Publishing a package:
npm publish

This command publishes the current package to the npm registry, making it available for others to install.

Getting Started

To get started with npm, follow these steps:

  1. Install Node.js, which includes npm, from https://nodejs.org/

  2. Create a new project directory and navigate to it:

    mkdir my-project
    cd my-project
    
  3. Initialize a new npm project:

    npm init -y
    
  4. Install a package:

    npm install express
    
  5. Create an index.js file and add the following code:

    const express = require('express');
    const app = express();
    const port = 3000;
    
    app.get('/', (req, res) => {
      res.send('Hello, npm!');
    });
    
    app.listen(port, () => {
      console.log(`Server running at http://localhost:${port}`);
    });
    
  6. Add a start script to package.json:

    "scripts": {
      "start": "node index.js"
    }
    
  7. Run the application:

    npm start
    

Your application is now running, and you can access it at http://localhost:3000.

Competitor Comparisons

41,396

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry

Pros of Yarn

  • Faster installation times due to parallel package downloads and caching
  • Improved security with checksum verification of packages
  • Cleaner and more informative CLI output

Cons of Yarn

  • Larger disk space usage for cache and offline mirror
  • Less frequent updates compared to npm
  • Some compatibility issues with certain npm packages

Code Comparison

Yarn:

dependencies:
  lodash: ^4.17.21
  react: ^17.0.2

scripts:
  start: yarn run dev
  build: yarn run build

npm:

{
  "dependencies": {
    "lodash": "^4.17.21",
    "react": "^17.0.2"
  },
  "scripts": {
    "start": "npm run dev",
    "build": "npm run build"
  }
}

Both Yarn and npm are popular package managers for JavaScript projects. Yarn was created to address some of npm's shortcomings, offering faster installation times and improved security features. However, npm has made significant improvements in recent versions, narrowing the gap between the two.

Yarn's parallel downloads and caching mechanism contribute to its speed advantage, while its checksum verification enhances security. On the other hand, Yarn's larger disk space usage and less frequent updates may be drawbacks for some users.

The code comparison shows subtle differences in configuration files and command syntax. Yarn uses a YAML-like format for its yarn.lock file, while npm uses JSON for package-lock.json. Both tools support similar commands and scripts, with minor variations in syntax.

Ultimately, the choice between Yarn and npm often comes down to personal preference and specific project requirements.

29,125

Fast, disk space efficient package manager

Pros of pnpm

  • Faster installation and updates due to efficient disk space usage and symlink-based structure
  • Stricter dependency management, preventing phantom dependencies
  • Smaller disk space usage with content-addressable storage

Cons of pnpm

  • Less widespread adoption and community support
  • Potential compatibility issues with some tools and workflows
  • Steeper learning curve for developers accustomed to npm

Code Comparison

npm:

{
  "dependencies": {
    "lodash": "^4.17.21"
  }
}

pnpm:

{
  "dependencies": {
    "lodash": "^4.17.21"
  },
  "pnpm": {
    "overrides": {
      "lodash": "4.17.21"
    }
  }
73,021

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Pros of Bun

  • Significantly faster package installation and project startup times
  • All-in-one solution: includes a package manager, bundler, and runtime
  • Native TypeScript support without additional configuration

Cons of Bun

  • Less mature ecosystem and community support
  • Limited compatibility with some existing Node.js packages and tools
  • Fewer available packages compared to npm's extensive registry

Code Comparison

Bun:

import { serve } from "bun";

serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello World!");
  },
});

npm/cli (using Node.js):

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World!');
});

server.listen(3000);

The Bun example demonstrates its more concise syntax and built-in server functionality, while the npm/cli example uses Node.js's standard http module. Bun's approach requires less boilerplate code and offers a more streamlined development experience.

10,872

Volta: JS Toolchains as Code. ⚡

Pros of Volta

  • Seamless version management across projects
  • Faster installation and execution of Node.js tools
  • Built-in support for multiple package managers (npm, Yarn, pnpm)

Cons of Volta

  • Smaller community and ecosystem compared to npm
  • Limited to Node.js tools, while npm supports a broader range of packages
  • Requires additional setup and learning curve for teams transitioning from npm

Code Comparison

Volta project configuration:

{
  "node": "14.15.0",
  "yarn": "1.22.10",
  "npm": "7.0.0"
}

npm project configuration:

{
  "engines": {
    "node": "14.15.0",
    "npm": "7.0.0"
  }
}

Volta offers a more concise and centralized approach to managing tool versions, while npm relies on the engines field in package.json for version specifications. Volta's configuration allows for easier management of multiple package managers within a single project.

Both CLI tools provide essential functionality for Node.js development, but Volta focuses on streamlining version management and tool execution, while npm offers a more comprehensive package management solution with a larger ecosystem.

78,700

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Pros of nvm

  • Allows easy switching between Node.js versions
  • Supports installation of multiple Node.js versions simultaneously
  • Provides a simple command-line interface for version management

Cons of nvm

  • Limited to Node.js version management only
  • Requires manual installation and setup
  • May introduce complexity for users who only need a single Node.js version

Code Comparison

nvm:

nvm install 14.17.0
nvm use 14.17.0
nvm alias default 14.17.0

npm:

npm install -g npm@latest
npm install package-name
npm run start

Key Differences

  • Purpose: nvm focuses on Node.js version management, while npm is a package manager for JavaScript
  • Scope: nvm operates at the system level, npm operates at the project level
  • Functionality: nvm switches between Node.js versions, npm manages dependencies and scripts

Use Cases

  • Use nvm when you need to work with multiple Node.js versions across different projects
  • Use npm for managing project dependencies, running scripts, and publishing packages

Integration

  • nvm and npm can be used together: install Node.js versions with nvm, then use npm for package management within each version
  • npm comes bundled with Node.js installations managed by nvm

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

npm - a JavaScript package manager

npm version license CI - cli Benchmark Suite

Requirements

One of the following versions of Node.js must be installed to run npm:

  • 18.x.x >= 18.17.0
  • 20.5.0 or higher

Installation

npm comes bundled with node, & most third-party distributions, by default. Officially supported downloads/distributions can be found at: nodejs.org/en/download

Direct Download

You can download & install npm directly from npmjs.com using our custom install.sh script:

curl -qL https://www.npmjs.com/install.sh | sh

Node Version Managers

If you're looking to manage multiple versions of Node.js &/or npm, consider using a node version manager

Usage

npm <command>

Links & Resources

  • Documentation - Official docs & how-tos for all things npm
    • Note: you can also search docs locally with npm help-search <query>
  • Bug Tracker - Search or submit bugs against the CLI
  • Roadmap - Track & follow along with our public roadmap
  • Community Feedback and Discussions - Contribute ideas & discussion around the npm registry, website & CLI
  • RFCs - Contribute ideas & specifications for the API/design of the npm CLI
  • Service Status - Monitor the current status & see incident reports for the website & registry
  • Project Status - See the health of all our maintained OSS projects in one view
  • Events Calendar - Keep track of our Open RFC calls, releases, meetups, conferences & more
  • Support - Experiencing problems with the npm website or registry? File a ticket here

Acknowledgments

  • npm is configured to use the npm Public Registry at https://registry.npmjs.org by default; Usage of this registry is subject to Terms of Use available at https://npmjs.com/policies/terms
  • You can configure npm to use any other compatible registry you prefer. You can read more about configuring third-party registries here

FAQ on Branding

Is it "npm" or "NPM" or "Npm"?

npm should never be capitalized unless it is being displayed in a location that is customarily all-capitals (ex. titles on man pages).

Is "npm" an acronym for "Node Package Manager"?

Contrary to popular belief, npm is not in fact an acronym for "Node Package Manager"; It is a recursive bacronymic abbreviation for "npm is not an acronym" (if the project was named "ninaa", then it would be an acronym). The precursor to npm was actually a bash utility named "pm", which was the shortform name of "pkgmakeinst" - a bash function that installed various things on various platforms. If npm were to ever have been considered an acronym, it would be as "node pm" or, potentially "new pm".

NPM DownloadsLast 30 Days