npm

Let’s understand what NPM is and how it handles all of our JavaScript packages for us.

Node package manager

Using a global import in the HTML file for third-party JavaScript libraries is convenient. However, it is generally not considered a best practice. As our applications start getting more complex and use more JavaScript libraries, managing them becomes much more complicated and unwieldy. Many popular JavaScript libraries may not even be available on a host site, so we need to utilize these libraries better.

We need to host these libraries ourselves as part of our application so that we don’t have to rely on third-party hosting of critical components of our applications. We’ll want to use a JavaScript package manager to manage these locally. One of the most popular today is Node Package Manager (npm).

Like pip for Python, we can use npm to download and install JavaScript libraries from the npm registry, which is similar to Python Package Index (PyPI) for Python libraries.

The npm manager Node.js is installed, which is a JavaScript runtime that allows us to run JavaScript programs outside a web browser.

Node and npm

Start the terminal widget below to check if we have Node.js installed. To do this, we can run this command in the terminal widget:

$ node -v

To confirm that npm is installed, we can also run this command in the terminal widget:

$ npm -v

Installation packages and binaries are available for Windows, Mac, and Linux. To ensure the best stability, ensure that we have the Long Term Support (LTS) version. Since it is an open-source project, the source code is also available.

Once Node.js and npm are installed, we can download JavaScript libraries from the npm registry using the Command Line Interface (CLI).

Get hands-on with 1200+ tech skills courses.