Introduction to NPM: The guide to setup and installation.

Introduction to NPM: The guide to setup and installation.

An easy way to set up node package manager(NPM) for your Javascript-based applications.

Before delving into this article, the term "package managers" might have come up in some of your learning materials and made you wonder what they are, so let's begin by discussing the use of package managers.

What is a package manager?

Package managers are used in installing, uninstalling, upgrading, or maintaining software packages based on the user's preference Examples of package managers are PIP(For python), NPM or yarn (For javascript based applications), etc. The main functions of a package manager can include:

  • Managing dependencies i.e.ensuring each package is installed with all the packages it requires.

  • installing, uninstalling, or updating existing software.

Now, that you have gotten that out of the way, let's get straight to business.

What is NPM?

Node package manager also known as NPM is a tool that is used to manage the dependencies present in your code, it can serve as one big storehouse or repository to store all the packages you might need in your code while using external libraries.

Before NPM, you would normally need to add a lot of script tags to your HTML file to be able to use code from external libraries which can turn out to be a huge mess in your code.

NPM provides an easier and faster way to use and manage packages from external sources in our code.

Installation of NPM

Checking if you have NPM installed already

To use NPM, you first need to have Node Js installed on your system. To check if you have Node Js installed on your system, simply open up your command prompt or terminal (if you use a MacBook) and type the command below inside the command prompt or terminal.

node -v

After typing in the command, if you get a response showing a certain number like the one in the image below, it means you already have Node Js installed on your system and thus have NPM installed too.

Note that the number shown doesn't have to be exactly the same as the one shown in the image, it can be any number.

When you download the Node Js app, it automatically installs the latest NPM version along with it. You can verify by typing the command below into your command prompt or terminal to confirm that you have NPM installed also:

npm -v

After typing the command, you should also get a response showing a certain number just like the former response, the number you get doesn't matter, what matters is that you get a number as a response and not an error message. Congratulations, you already have Node Js and NPM installed on your machine and might want to stop reading this article at this point which is fine.

However, if you got an error message while running any of the commands above, it means Node Js is not installed on your device, so what you should do is download Node Js and install it on your device to be able to use NPM.

Downloading and installing Node Js

To download Node Js, you have to visit their website at nodejs.org and download the latest version of Node Js suitable for your computer operating system. There might be a different version of Node Js for Windows, Linux, and Mac operating systems on the site, So check carefully for the one which is most suitable for your device and download it.

After successfully downloading Node Js, you can install it following the installation procedure on your device which will make it ready for use on your device.

After you have successfully installed Node Js, NPM should also have automatically been installed alongside it. You can verify this by running the previous commands to check if they were both installed properly. See the commands below:

node -v

npm -v

Running each of these commands separately should each produce a number as a response which then proves that you have successfully installed NPM on your device and can now use it to manage all your dependencies in your code thereby making your coding experience easier and faster.

Conclusion

We have come to the end of this article and by now you should already have NPM available for use on your computer. If you are still having issues installing NPM after reading this article, try reading the docs section on the Node Js page to see if you can discover what the error is. It might also be an issue with the compatibility of the version you downloaded with your operating system, so you might also want to do research on the NPM or Node Js versions compatible with your device and download them.

Thank you for reading this article, please leave a like or follow if this article was helpful to you in any way.