Node.js Package Manager (npm)

📘 Node.js 👁 54 views 📅 Nov 05, 2025
⏱ Estimated reading time: 2 min

npm (Node Package Manager) is the default tool used with Node.js to install, manage, and share JavaScript libraries.
It connects developers to a large ecosystem of reusable open-source packages.


1. Why npm Is Important

  • Eliminates the need to write everything from scratch

  • Manages project dependencies automatically

  • Ensures consistent versions across environments

  • Speeds up development


2. Main Components of npm

2.1 npm Registry

  • Online database containing thousands of packages

  • Hosts public and private libraries


2.2 npm CLI

  • Command-line tool used to interact with npm

  • Installed automatically with Node.js


2.3 package.json

  • Configuration file that describes the project

  • Stores dependencies, scripts, and metadata

Example:

{ "name": "sample-app", "version": "1.0.0", "scripts": { "start": "node app.js" } }

3. Installing Packages

Local Installation (Project-specific)

npm install lodash

Global Installation

npm install -g nodemon

4. Dependency Types

TypePurpose
dependenciesRequired for production
devDependenciesNeeded only for development
optionalDependenciesNon-critical packages

5. Version Control & Semantic Versioning

Example:

"express": "^4.18.0"
  • ^ → updates minor versions

  • ~ → updates patch versions


6. node_modules Folder

  • Stores all installed packages

  • Can be large

  • Not committed to version control


7. npm Scripts

Automate tasks using scripts.

"scripts": { "start": "node index.js", "test": "echo Testing..." }

Run with:

npm run start

8. Updating & Removing Packages

Update:

npm update express

Uninstall:

npm uninstall express

9. Package Lock File (package-lock.json)

  • Records exact versions of installed packages

  • Ensures identical installs across systems

  • Improves security and consistency


10. Publishing Packages

npm allows developers to publish their own packages:

npm login npm publish

11. Advantages of npm

  • Huge ecosystem

  • Easy dependency management

  • Version control support

  • Strong community


12. Summary

  • npm is the backbone of the Node.js ecosystem

  • Manages libraries, tools, and project scripts

  • Uses package.json and package-lock.json

  • Essential for modern JavaScript development


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes