npm install and uninstall

npm install and npm uninstall

For those not familiar, npm is the Node Package Manager. While not the only package manager available, it is the one that ships with Node by default. Technically, npm is both a registry (list of packages) and a command line tool (used to npm install and npm uninstall those packages).

The command line tool has a ton of functionality, which I cover in my free introduction to npm course. Today, we’re just going to focus on two of those commands, npm install and npm uninstall.

Initializing an npm project

In the next two sections we’re going to talk about the multiple ways you can install and uninstall packages with npm’s command line tool. For some of the approaches (all except installing/uninstalling globally) you’ll need a package.json file in your project.

If you’re not familiar with package.json files, check out my free course! (plug plug plug) but the gist of it is that you’ll need to run an npm init in your project like so:

npm install

There are three ways you can install software using npm’s command line tool. They are:

1. Install a package globally, so that you can use it at any time from the command line:

2. Install a package locally, saving it to your project’s package.json:

3. Install package locally, marking it as a “dev dependency”

Dev Dependencies

Installing something as a dev dependency means that it is necessary for building the app, but is not to be deployed to production. A good example of this would be a build tool like gulp or grunt, which you need to build your assets but you don’t need to install on your production servers.

In action, the difference between –save and –save-dev is that packages installed with the –save-dev flag will not be installed when a user runs:

However, it will still be installed on a regular install.

npm uninstall

npm has a well designed API, so all of the uninstall commands map directly to their install counterparts! Here are the appropriate examples:

1. Uninstall a package globally, so that you can no longer use it from the command line:

2. Uninstall a package locally, removing it from your project’s package.json:

3. Uninstall package locally, removing it as a “dev dependency”

Jon Kuperman

Jon Kuperman is a Programmer, Teacher and Entrepreneur. He's currently blogging at Code Planet and podcasting at The Web Behind.

Leave a Reply

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