NPM

Shameera Carrim
2 min readSep 9, 2023

--

Ever wondered what NPM is and why it’s a must-know tool for JavaScript developers? 😐

NPM, short for Node Package Manager. NPM is the go-to solution for managing packages and dependencies in your Node.js projects. In this article, we’ll dive into the importance of NPM and guide you through the process of installing and managing packages.

Importance of NPM

  1. Package management — In software development, projects often rely on external libraries and code modules. NPM makes it easy to discover, install, and keep track of these dependencies. Devs do not have to waste time manually downloading and organizing libraries.
  2. Version Control and Dependency Resolution — It ensures project uses the correct versions of packages, it can specify the exact version or a version range for each dependency, preventing compatibility issues. When you run npm install, NPM automatically resolves and installs the appropriate versions, saving you from potential obstacles down the road.

Installing and Managing Packages

Prerequisite*

You have to install Node.js. NPM is bundled with it. Once installed we can access NPM.

To check node is installed we can execute below command in terminal

npm -v

This command should display the installed NPM version. If it’s not installed, you can download and install Node.js from the official website (https://nodejs.org/), which includes NPM.

Creating a node project

To start using NPM in your project, you first need to initialize a package.json file. This file serves as a manifest for your project, listing its metadata and dependencies.

Navigate to your project directory/folder and open up the terminal and type npm init. This will create a package.json file.

Adding a dependency

Below command will install the relevant package to the node project.

npm install package-name --save

If you’re installing a package for development purposes, such as a testing library or build tool, you can use the --save-dev flag:

npm install package-name --save-dev

This ensures that the package is listed under the dependencies or devDependencies section of your package.json, depending on the flag you used.

Updating Packages

To keep your project up to date with the latest package versions, you can use the npm update command:

npm update

Read more about NPM from official website (https://docs.npmjs.com/cli/v6/commands/npm-install)

There are alternatives to NPM.

Few of the package managers are;

Yarn:

  • Developed by Facebook.
  • Faster and more secure than NPM.

pnpm:

  • Space-efficient package manager.
  • Uses a shared global store.
  • Faster installations and removes unused packages.

Bower:

  • Front-end package manager.
  • Designed for managing web assets.
  • Useful for front-end libraries and assets.

Even though there are alternatives, devs still use NPM .With NPM you’ll find that building and maintaining Node.js applications becomes very efficient. So, go ahead and build node projects using the power of NPM. 🔥

--

--