Node.js packages (npm)

Overview of NPM (Node Package Manager)

npm is a package manager that helps to organize and share Node.js packages and modules. NPM can download packages and check for updates to packages you already have installed.

This article is a quick overview of Node.js packages. For further information, view the following page from docs.npmjs.com:

Prerequisites

Installing Node.js and npm

Node.js is not installed by default on newer DreamHost servers. You must manually install a custom version under your server's username. View the following article for instructions on how to install a custom version of Node.js.

Once installed, npm is also installed and you'll be able to run the commands below.

Updating npm

Check the version by running the following command:

[server]$ npm -v

To update npm to the latest version, run the following command:

[server]$ npm install npm@latest -g

Run the following command to check the directory npm writes to.

[server]$ npm config get prefix
/home/exampleuser/.nvm/versions/node/v12.16.3

If you installed NVM as shown above, you'll see the directory response as the /.nvm folder under your current user.

What are packages?

A package is one or more .js files (modules) grouped (or packaged) together. The files in a package are reusable code that perform a specific function for your Node.js app. This page lists the most popular packages:

Downloading and using packages allows you to add code and functionality to your site without having to build it yourself.

Where to find packages

You can browse packages on the Node.js website:

Local or global installation?

You can install packages locally or globally. It depends on how you want to use the package.

Local

The default behavior of running npm install is to install locally. This is preferred if you're going to use require to depend on the package from your own module.

Globally

If you want to use the package as a command line tool.

Checking which packages are installed

Local packages

To check which local packages are installed, navigate to your site's application directory where the /node_modules folder resides. Then run the following:

[server]$ ls node_modules

Global packages

Run the following:

[server]$ npm ls -g --depth=0

Installing packages

View the following page for instructions on how to install packages locally or globally:

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?