</>
Skip to content
Node.js lessons (10/44)

Node.js — NPM

What is npm?

npm is the default package manager for Node.js.

Basic Commands

npm init                    # Initialize project
npm install express         # Install package
npm install express@4.18    # Install specific version
npm install -D nodemon      # Install dev dependency
npm uninstall express       # Remove package
npm update                  # Update packages

package.json

{
  "name": "my-app",
  "version": "1.0.0",
  "description": "My application",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "jest"
  },
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "nodemon": "^3.0.0"
  }
}

npm Scripts

{
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "build": "webpack --mode production",
    "test": "jest --coverage"
  }
}
npm start
npm run dev
npm run build

package-lock.json

Locks exact versions of dependencies for reproducible builds.

npm Registry

npm search express
npm info express
npm view express version

Mini Practice

  1. Initialize a new project
  2. Install a package
  3. Create npm scripts
  4. Update packages

Up Next

Continue with Packages — working with npm packages.

Related Topics

Frequently Asked Questions about NPM

What is NPM in Node.js?

NPM is a fundamental concept in Node.js. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn NPM?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn NPM.

Why is NPM important in Node.js?

NPM is essential for Node.js development. Understanding this concept will help you write better code and solve real-world problems more effectively.