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.
Eliminates the need to write everything from scratch
Manages project dependencies automatically
Ensures consistent versions across environments
Speeds up development
Online database containing thousands of packages
Hosts public and private libraries
Command-line tool used to interact with npm
Installed automatically with Node.js
package.jsonConfiguration file that describes the project
Stores dependencies, scripts, and metadata
Example:
| Type | Purpose |
|---|---|
dependencies | Required for production |
devDependencies | Needed only for development |
optionalDependencies | Non-critical packages |
Example:
^ → updates minor versions
~ → updates patch versions
node_modules FolderStores all installed packages
Can be large
Not committed to version control
Automate tasks using scripts.
Run with:
Update:
Uninstall:
package-lock.json)Records exact versions of installed packages
Ensures identical installs across systems
Improves security and consistency
npm allows developers to publish their own packages:
Huge ecosystem
Easy dependency management
Version control support
Strong community
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
Take quizzes related to this topic and see where you stand!
Start Quiz Now