🔍 What is npm?

npm stands for Node Package Manager. It is a tool that helps developers install, share, and manage packages (libraries) for Node.js projects.

Example:

// Installing a package
// Run this in the terminal
npm install express

This installs the Express library so you can build web applications faster.

📄 What is package-lock.json?

The package-lock.json file keeps an exact record of the versions of all installed packages and their dependencies.

Example snippet from package-lock.json:

{
  "name": "my-app",
  "version": "1.0.0",
  "lockfileVersion": 2,
  "dependencies": {
    "express": {
      "version": "4.17.1",
      "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz"
    }
  }
}

This ensures express will always be installed as version 4.17.1.

⚡ What is npm ci?

The npm ci command is used to install dependencies in a clean, predictable way.

Example:

// Using npm ci in a terminal
npm ci

This ensures the dependencies match exactly what is in package-lock.json for stable builds.

📊 npm install vs npm ci

Feature npm install npm ci
Speed Slower Faster
Uses package-lock Yes Yes
Cleans node_modules No Yes
Predictable builds Sometimes Always

📝 Summary

In Node.js projects, npm is the package manager that installs and manages libraries, package-lock.json ensures exact version consistency, and npm ci installs packages in a clean, predictable way ideal for automated environments. Together, they make dependency management faster, more reliable, and easier to maintain.