Node.js: Code Outside the Browser / Working with npm (Node Package Manager)

What is npm and why use it?

πŸ“¦ What is npm?

  • npm stands for Node Package Manager.

  • It's the default package manager bundled with Node.js β€” installing Node automatically gives you npm.

  • Lets you install, manage, update, and share reusable code, called "packages" or "modules."

🧠 Think of it as a massive online registry of libraries and tools built by other developers, ready to plug into your app instead of building everything yourself.


βš™οΈ What npm Actually Does

  • Installs packages β€” pulls code from the npm registry into your project.

  • Tracks versions β€” records exactly which version of each package your project uses.

  • Manages dependencies β€” handles the web of packages-that-depend-on-other-packages automatically.

  • Runs scripts β€” lets you define custom commands (like npm start or npm run build) in package.json.


πŸ€” Why Use npm?

  • Avoid reinventing the wheel β€” use express instead of writing a full server from scratch.

  • Share your own libraries β€” publish your own packages for others (or your future self) to reuse.

  • Easily manage project dependencies β€” one file (package.json) tracks everything your project needs.

  • Stay up to date β€” update packages and pull in bug fixes or new features with a single command.


🌐 npm Has Three Parts

  • The registry β€” the online database where packages live (like github)

  • The CLI β€” the npm command you run in your terminal.

  • The website β€” npmjs.com, where you can browse and search packages.