Protractor Tutorial 8 – NPM – Updating Global and Local Package

Hello Folks,

In last post we have seen how can we install NodeJS package locally and globally.

In this post we will learn:-

  1. How to check if a package is outdated?
  2. How to update locally installed package?
  3. How to update globally installed package?

Check for outdated package:-

Before checking for the outdated package, let’s install outdated package locally and globally.

Installing outdated package globally:-

We will install outdated version of xlsx NodeJS package. Current version of xlsx is 0.14.3 but we will install 0.13.0:-

You can list global package without depth using npm list -g -depth=0

Installing outdated package locally:-

We will install same xlsx package but different outdated version i.e. 0.14.0:-

You can list locally installed package without its dependent packages using npm list -depth=0

NPM OUTDATED command:-

We have a command to check the registry to see if any (or, specific) installed packages are currently outdated. Command is as below:-

npm outdated [[<@scope>/]<pkg> …]

Let’s run it at both locally and globally:-

Local:

Global:-

You can see that above commands gives you some details. Let’s see meaning of each field:-

Package: – Installed NodeJS package name.

Current:- The currently installed version of package in your system.

Wanted:- It is the maximum version of the package that satisfies the semver range specified in package.json. If there’s no available semver range (i.e. you’re running npm outdated --global, or the package isn’t included in package.json), then wanted shows the currently-installed version or close-by version.

Latest:- It is the version of the package tagged as latest in the registry.

Location:- It is where in the dependency tree the package is located.

Now understand result of outdated commands above:-

Locally:

We do not have any package.json in local folder. So “Wanted” field is showing “0.14.3” which is close-by version of installed version “0.14.0”.

Globally:-

Like local, when we run outdated command for global package, “Wanted” will also give close-by version. So “Wanted” field is showing “0.13.5” which is close-by version of installed version “0.13.0”.

Read more about outdated command here.

Updating Packages:-

NPM provides a command to update package/s which is below:-

npm update [-g] [<pkg>…]

This command will update all the packages listed to the latest version (specified by the tagconfig), respecting semver. If the -g flag is specified, this command will update globally installed packages. If no package name is specified, all packages in the specified location (global or local) will be updated.

To update a specific package, pass package name with command as:-

npm update <packageName>

Let’s update all package in global and local:-

Global:-

Package was updated to version mentioned in “Wanted” field.

Local:-

You will also find same behavior as global here:-

When you have latest installed, you will not get any output for npm outdated command.

Anyway above concept will change if package.json exists. We will see those as well in upcoming posts.

You may find it little confusing. Raise questions/doubts/concerns if any.

#ThanksForReading

Leave a Reply

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