JavaScript

NPM & Package Management

Tap into the world's largest software registry! Learn to use npm to install, manage, and share packages.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Tap into the world's largest software registry! Learn to use npm to install, manage, and share packages. This hands-on tutorial focuses on practical implementation of npm & package management concepts.

NPM & Package Management

NPM stands for Node Package Manager. It is the "App Store" for JavaScript developers.

Instead of writing everything from scratch (like date formatting, math functions, or server logic), you can download code written by others.

1. What is NPM? πŸ“¦

It consists of three parts:

  1. The Website: Browse millions of packages (libraries).
  2. The Registry: A huge database where packages are stored.
  3. The CLI (Command Line Interface): A tool to install and manage packages.

2. The package.json File πŸ“„

Every Node.js project starts with this file. It's the ID card of your project.

How to create it: Run npm init -y in your terminal.

JSON PLAYGROUND
⏳ Loading editor…

Key Fields:

  • name: Your project's name.
  • version: Current version (e.g., 1.0.0).
  • scripts: Shortcuts for terminal commands (e.g., npm start).
  • dependencies: List of external packages your project uses.

3. Installing Packages ⬇️

To use a library (like lodash for utility functions), you install it.

Command: npm install <package_name>

This does two things:

  1. Downloads the code into a folder called node_modules.
  2. Adds the package name and version to your package.json.
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Dependencies vs. DevDependencies πŸ—‚οΈ

Not all packages are needed for your app to run. Some are just for building or testing.

  • Dependencies (npm install <pkg>):

    • Required for the app to run (e.g., express, react, mongoose).
    • Installed on the production server.
  • DevDependencies (npm install -D <pkg>):

    • Only needed during development (e.g., jest for testing, nodemon for auto-restart, eslint for linting).
    • NOT installed on production.

5. Semantic Versioning (SemVer) 🏷️

Version numbers look like 1.2.3. They have a specific meaning:

  • Major (1.x.x): Breaking changes. (Code might stop working).
  • Minor (x.2.x): New features (Backward compatible).
  • Patch (x.x.3): Bug fixes (Backward compatible).

The Caret (^) Symbol: In package.json, you'll see "lodash": "^4.17.21". The ^ means: "It's safe to update Minor and Patch versions, but DO NOT update the Major version."

AI Mentor

Confused about "NPM, package.json, dependencies vs devDependencies, and semantic versioning"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

Which command creates a package.json file?

npm create
npm init -y
npm start
npm install

Key Takeaways

βœ… npm init -y starts a project.
βœ… npm install adds packages.
βœ… node_modules is where code lives (don't touch it!).
βœ… DevDependencies are for tools, not the app itself.
βœ… SemVer keeps your app from breaking when updating.

What's Next?

Now that we can install packages, how do we actually use them? Let's master Node Modules (CommonJS vs ES Modules)!

Keep coding! πŸš€