Node Package Manager: Details, Commands and Installation

Node Package Manager

What is node package manager?. If you’re building an app with JavaScript, but need one important feature? Well, if you don’t want to make it yourself because it takes a long time, NPM is the solution.

With NPM, you can get various JavaScript packages needed to support your project. So, the process of creating your application can be faster.

But, what exactly is NPM?

Well, you have found the right article. This time, we will discuss the NPM tutorial to understand the NPM package for building projects. Here, you will learn understanding, commands and how to install NPM.

What is NPM?

NPM is the Node Package Manager, which is Node.js’ built-in JavaScript package manager. Package manager itself is a tool that functions to manage packages automatically.

So, when building an application with JavaScript, you no longer need to manually download the required dependency packages, including verifying the version number.

NPM has two functions as a package manager.

First, NPM is a repository. This means that NPM acts as a platform where people can share their JavaScript packages on npmjs.org. You can also do that with your custom pack.

With NPM functioning as a repository, you can download the necessary packages to support your project at any time. Therefore, you do not need to create various features in the application from scratch.

Second, NPM also functions as a command line interface (CLI). This is a tool for typing commands to manage, download, and upload JavaScript packages. It looks similar to Command Prompt on Windows or Terminal on Linux.

How does it Works?

The way NPM works is in accordance with the two functions it has.

First, the way NPM works is like a repository like Google Drive or Dropbox, but specifically for storing JavaScript packages. You can make it available to other NPM users, or keep it for your own use.

If the way NPM works as a CLI or tool is to manage packages available in the NPM repository. By running certain commands through these tools, you can download, upload, update, and other actions related to the NPM package.

For example, you are writing a program and need an async module to work with asynchronous JavaScript. All you need to do is type npm install async. Then you can use async functions like require() in the program.

To use NPM, your project must have a package.json file, which contains metadata such as:

  • The project name
  • Version
  • description
  • entry point
  • test command
  • git repository
  • Keywords
  • Licence
  • Dependencies
  • devDependency

Well, in the next section, you will learn some of the NPM commands needed to start using NPM.

Basic Node Package Manager Commands

Below is a list of the basic NPM commands you need to know:

CommandsFunctions
npm initCreate a package.json file
npm installInstalls all packages listed in package.json.
npm install <package-name>Installs the latest version of the package you specified to the folder node_modules.
npm install <package-name>@<version>Installs the package with the version you specified to the node_modules folder.
npm install -g <package-name>Install packages globally. This means that the package you install can be used in other projects besides the one you are currently working on.
npm install –save <package-name>Installs the package locally and adds it as a dependency in the package.json file. Locale here means that the package is only installed in the project you are currently working on.
npm install –save-dev <package-name>Installed the package locally and added it as a devdependency in the package.json file.
npm uninstall <package-name>Uninstalling the latest version of the package.
npm uninstall <package-name>@<version>Uninstalls the package with the version you specified.
npm uninstall -g <package-name>npm uninstall -g <package-name>
npm uninstall –save <package-name>Uninstalls the package and removes it from the dependency list.
npm uninstall –save-dev <package-name>Uninstalls the package and removes it from the devdependency list.
npm search <keyword>Search for packages in NPM according to the keywords you specify.
npm update -g <package-name>Updating your specified package globally.
npm update <package-name>Updating the package you specified locally.
npm update –dev <package-name>Updating the devdependency you specified.
npm help <command>Displays a description of the command you specified.
npm docs <package-name>Opens the documentation related to the package you specified.
npm bugs <package-name>Indicates a bug in the package you specified.
npm repo <package-name>Opens the NPM repository page for the package you specified.
npm lsDisplays the version and list of dependencies of all packages in the local installation.

How to Install NPM in Windows

To install Node.js on Windows, follow these steps:

Download and Run the Node.js Installer

1. Download and Run the Node.js Installer

Download the Node.js installer on this page as you need.

How to Install NPM in Windows

Choose the LTS version for general use with more stable features. Select Current version to download the latest Node.js version with the latest features.

After downloading, run the installer and follow the installation steps to complete.

2. Check NPM and Node.js Installation

To make sure Node.js and NPM are installed properly, you can run the command node -v and npm -v in the Command Prompt. Because both commands will display the installed versions of Node.js and NPM.

How to Install NPM Mac

To install NPM on a Mac, follow these steps:

1. Download and Run the Node.js Installer

Go to this page and click macOS Installer to download the Node.js installer for Mac.

2. Check Node.js Installation

Open Terminal and run node -v command to confirm Node.js installation.

3. Update NPM Version

When Node.js is installed on a Mac, the NPM version doesn’t automatically update. Therefore, you need to do it manually by running the below command:

$ sudo npm install npm --global
4. Installing NPM Module

After the NPM installation is complete, you must first install the module or library according to your project needs.

For example, if you want to use React, you need to install the React module.

It’s easy, you just run the command below:

npm install

Or

npm i

Conclusion

NPM is a JavaScript package manager built into Node.js. With NPM, you can download various JavaScript packages to speed up application development.

Read More :

Npm has many uses. Especially if you are using React JS for your project.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like