[Node.js] NPM Demystified Part-3 : npm update and npm outdated comments explained in detail.


Let's update our index.js with following code snippet.

var _ = require('lodash');
console.log(_.compact([0, 1, false, 2, '', 3]));

Just comment the existing code, Let us go through the above two lines of code then we will revert back to our old code.

Save the index.js and run "npm start"

Output will be: [ 1, 2, 3 ]

The compact method is part of lodash, It will remove the falsy value present in an Array i.e(null, false, 0, undefined, ""). Just, for example, we have used this method.

Want to know more about methods available in lodash? refer this url : https://lodash.com/docs/

👏👏Great!! Hereby we have managed to add external node module and able to access method present in that external module.

npm outdated

Next, we will look into npm outdated command. To demonstrate this command I'm degrading the version of lodash. When we run npm outdated output will be.

npm outdated

Package  Current  Wanted  Latest  Location
lodash    4.13.0  4.13.0  4.17.4  nodeapp

We can find the outdated packages with this command.

☝☝Questions: How you reduced the version of lodash?
Updated the package.json such that

"dependencies": {
  "lodash": "^4.17.3"
}

"dependencies": {
  "lodash": "^4.13.0"
}

After modification just do npm install, npm will install the package version mentioned in the package.json. then try running npm outdated you will get above error.


npm update

In the above example, you can find the current version of lodash installed with our application is 4.13.0. You can check the version by the following command as well. 

npm ls

You can find following output.
nodeapp@1.0.0
└── lodash@4.13.0

Now just run npm update, Since I have used ^ before version it will update my lodash package to a latest minor version which is 4.17.3.

npm update

nodeapp@1.0.0

└── lodash@4.17.4 

if you have used * for version, it will update to latest major version.

In this post, we have learned the usage of external node module and we accessed methods available in that module. Then we learned three important npm commands.
npm outdated
npm ls
npm update

In the next chapter, we will go through remaining commands available with npm.

Please share your comments or questions in the below comment section!!👍👍👍

Comments