npm CLI

11.12.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic 'npm' command-line usage for initializing a project, installing local and global dependencies, and running package.json scripts.

// 1. Initialize a new Node.js project (if you don't have one)
//    This creates a package.json file.
// In your terminal:
// npm init -y

// 2. Install a common development dependency, e.g., 'lodash'
// In your terminal:
// npm install lodash

// 3. Install a global utility, e.g., 'nodemon' (for development servers)
// In your terminal:
// npm install -g nodemon

// 4. Create a simple JavaScript file (e.g., index.js)
// console.log('Hello from npm-managed project!');
// const _ = require('lodash');
// console.log(_.camelCase('hello world'));

// 5. Add a 'start' script to your package.json:
/*
{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "lodash": "^4.17.21"
  }
}
*/

// 6. Run your project scripts
// In your terminal:
// npm start
// npm run dev (if nodemon is installed globally or locally)

view raw JSON →