If you are familiar with JavaScript or Web Development then you must have heard about npm. NPM helps us to manage packages and dependencies in our projects. So, while learning a JavaScript framework the knowledge of npm would be really useful to learn it in an easier manner.
In this series of articles, we aimed to cover the following topics:
- Important ES6 Features
- Objects and Array methods
- Asynchronous JavaScript and Fetch API
- NPM and import/export modules in JavaScript (this article)
Let’s first start with NPM:
NPM
What is NPM?
NPM is the default package manager for node. It is used to install, share, and manage javascript packages in a project.
NPM has three components:
- The website (Using the website we can find, share, and view packages)
- The Command Line Interface (CLI) (The CLI is the component that helps us in managing our packages)
- The registry (The npm registry is the database where all the packages exist, we can download packages published by other developers and can also publish our own packages to the registry)
Note:
- NPM can also be used to publish and manage private packages.
- A package is simply a program that performs one or more operations.
How to Install npm?
NPM comes pre-installed with node.js. So, you don’t need to worry about installing it manually, you just have to install node.js on your system.
To install node.js, visit https://nodejs.org/en/download, and install its LTS (Long Term Support) version.
After installation, use the commands shown below to check if they are installed:
// to check nodejs's version
node -v or node --version
// to check npm's version
npm -v or npm --version
This will result in something like this:
package.json
The package.json file is like the manifest of your project. It makes it easier to install and manage packages. It consists of all the metadata of the project that will be useful while sharing the project with other developers.
According to the official docs:
A package.json file:
- lists the packages your project depends on
- specifies versions of a package that your project can use using semantic versioning rules
- makes your build reproducible, and therefore easier to share with other developers
Top comments (1)
Maybe it's just me but is posting only half article and link it to other even legal here? Btw, medium blocks me (or my country blocks medium - unsure) so I can't really read yours. Just sharing a reason why I don't think it is right to share a bait article like this in here.