The Basics of npm
Published: 2023-10-13 01:27:22

## Introduction

**Node Package Manager(npm)** is a popular package manager used for JavaScript. It was made to go along with Node.js. Npm is used for the installation and management of JavaScript libraries and tools, which allows developers to easily be able to access useful tools to help them in their projects. It was made for developers who don't really need anything special when it comes to package management, and just need a simple tool that they can use and not have to think about again.

## History and Alternatives 

Npm was released in 2010 by Isaac Z. Schlueter, but since then, the software development community has evolved to need different types of package managers. Npm is not necessarily a one-size-fits-all when it comes to package management. This is where package managers such as **Yarn** come in.

## Yarn

**Yarn** is a newer package manager released in 2016 by engineers from Facebook and Google who collaborated to design a faster alternative to npm. Not only is Yarn faster for the installation of packages, but it also has several other advantages over npm. Yarn does not need to be configured as much as npm, has improved package integrity, and even has an offline mode to work on the go without Wifi. This isn't to say that Yarn is better than npm, but that it has features that could be preferable to some people over npm. 

## Improvements to npm

Over the years, npm has improved with new features since its release. It has added features such as security to help find corrupt files and better installation times. It worked off of its flaws and improved upon them to make the manager better and more efficient. Eventually, it became equal if not better than what Yarn improved on with npm.

## How to Install npm

To get started with using npm, visit [nodejs.org](https://nodejs.org/en) and install Node.js for free. npm should automatically be installed with Node.js since it is the default package manager. To make sure, you can run:

```
npm -v
```
If a version number appears, then you have successfully installed npm. 

## How to Use npm

Since you now have npm installed, you can use it to download libraries and tools in the form of packages. 

1. You can go to your desired website and find their download instructions. 

2. You will likely end up with a code that looks like the following:

```
npm install "package"
```

3. The word "package" will be replaced by whatever specific package you are downloading. Go to the terminal in your project and paste the command. 

4. If all goes well, you will have successfully installed your package.

## Example:

As an example, allow me to demonstrate how to download Mocha.js, a library that adds testing capabilities. All I need to do is go to the website for the Mocha library, and find the code I need to copy. In this case it is "npm install mocha". As you can see, I have successfully installed Mocha. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyywx80l13z7jah3jsz1.png)


Another example of how to use npm is downloading a package is this really interesting package I found called Elevator.js. It eliminates the need to scroll to the top of a document by adding a button and adds elevator music when you click it. All I need to do is type in this code and as you can see, it is installed.  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4s9f2njtvvfpgscdk9d.png)

## Conclusion

As you can see, npm is very versatile and useful for downloading tools and packages. Because of npm and other package managers, software developers are easily able to install what they need without the hassle of manually importing files into their code.