Introduction to NPM (Node Package Manager)

Home / Introduction to NPM (Node Package Manager)

Introduction to NPM (Node Package Manager)

December 9, 2015 | Article | 1 Comment

NPM (Node Package Manager) or simply npm is a simple application to install node programs. NPM also support a feature which will indicate dependencies and package starting file.

In this article, we will discuss about how to use npm, from a basic command to a rather advance one.

Getting Help

npm has a lot of feature, therefore let’s start by knowing how to get a help. NPM has a lot of help documentation about all of its command. Getting a help is as simple as typing this command on your terminal:

npm help

If you have a problem with any of npm command/feature, you can append –help on the command, leading to a documentation specific to that command. For example, both are valid command:

npm help install
npm install --help

Filtering Packages

npm ls [filter]

NPM can see the list of all packages and their version (npm ls with no filter), or filter by a tag (npm filter tag). For examples:

Installed Package

npm ls installed

This will list all installed package.

Stable Package

npm ls stable

This will list all stable package available (installed or not).

Search by Content

npm ls name

This way, we can have all packages that have “name” inside its name or tags.

Search by Version

npm ls @1.0

This is used to query packages specified by its version.

Install a Package

NPM is used to install,update, and remove a package. That’s what a package managers do.

When we want to install something, we can use following command and let NPM install the latest version of it to our machine. Here we will have “pkg_name” installed on our system.

npm install pkg_name

You can also install from a tarball, a folder, or an url to a tarball. If you run npm install without arguments, it tries to install the current folder. For example, we will install express:

npm install express

Or we can also install a specific version of a package by:

npm install [email protected]

We can also install the latest of a package within a version range we specify. For instance:

npm install [email protected]">=0.1.0"

More filters can be used to select a specific packages.

Update Packages

npm update [pkg_name]

The update command does a few things:

  1. Search the registry for new versions of all the packages installed (if pkg_name is omitted) or specific packages.
  2. If there’s a newer version, then install it
  3. Point dependent packages at the new version, if it satisfies their dependency
  4. Remove old versions, if no other package names them as a dependency.

Basically, update behaves a lot like a “standard” package manager’s update command, except that it also checks to make sure that the new version isn’t going to break anything before it points stuff at it.

Remove Packages

This command will uninstall a package. If the version are omitted, then all the found version are removed.

npm rm pkg_name[@version] [pkg_name2[@version]]

Read Package Information

To view all of a package information, we can do like this:

npm view pkg_name[@version]

,

About Author

about author

xathrya

A man who is obsessed to low level technology.

1 Comment
  1. Introduction to NodeJS Modules - Xathrya.ID

    […] Third party module is installed using NPM. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial