NPM
What is NPM?
NPM is short for Node Package Manager. According to nodejs.org, NPM is essentially two things:
- First, an online repository for the publishing of open-source Node.js projects
- Second, a command-line utility for interacting with said repository that aids in package installation, varsion management, and dependency management.
In other words, NPM is a place where any developer can publish their software and where any developer can use that software. On top of that, NPM is free to use.
What benefits does NPM provide and why is it important?
NPM is beneficial and important because the different software available to developers facilitates the development process. Perhaps the most important part of NPM is that you can specify all of your project’s dependencies inside your package.json file. That means that anytime you or someone else needs to get started with your project, they can just run npm install
and immediately have all of the dependencies installed.
How do you use NPM?
In order to use NPM, you have to install it on your computer. From your computer’s terminal you will type:
npm install npm -g
This will globally install NPM to your computer so that you can use it anywhere. If you only want to install NPM in a specific folder, you would navigate to that folder in the terminal and type:
npm install npm
To check what version of NPM and Node.js you have installed on your computer, simply type:
node -v
npm -v
Downloading a package from NPM is simple as well. All you have to do is find the package you wish to install on npmjs.org and follow the instruction for that specific package. For example, if I wanted to install Bootstrap I would navigate to my project in the terminal and type:
npm install bootstrap
What is the difference between a package and a module?
A package is a file or directory that is described by a package.json file. In order for a package to be published to the NPM registry it must contain a package.json file. The package.json file will include metadata about the package. A package is made up of modules. A module is a single file that has some functionality.
How can you use NPM on the frontend?
The uses of NPM on the frontend are limitless. You could use NPM to install something like React, a JavaScript famework that uses components. Or you could install Bootstrap which works with CSS and facilitates styling.
What are the 3 components of NPM?
According to the NPM docs, the three components of NPM are:
- The website
- The Command Line Interface (CLI)
- The registry
The NPM website is used to discover packages, create profiles, and manage other parts of your NPM experience
The CLI runs from the terminal on your computer and it is how developers download and install packages.
The registry is a large public database of JavaScript software and the meta-information surrounding it.