Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you quickly check if you package.json file has modules that could be updated to newer versions?

Tags:

node.js

npm

How can you quickly check if you package.json file has modules that could be updated to newer versions?

For example, a quick way to check if either express or nodemailer has an available update?

{
    "name": "some_module_name"
  , "description": ""
  , "version": "0.0.3"
  , "dependencies":  {
           "express": "3.1"
         , "nodemailer" : "0.4.0"
    }
}

I read over the FAQs, but didn't see anything: https://npmjs.org/doc/faq.html

Thanks.

like image 561
cathy.sasaki Avatar asked May 07 '13 15:05

cathy.sasaki


People also ask

How do you update a specific package in package json?

To update a specific package, we need to run the npm update command followed by the package name. Sometimes, you want to update a package to the specific version in such cases you need to use npm install command by specifying a version number after the package name.

Can I update package json?

Updating packages to the most recent major version json to the latest major version if they are sure that the project will still work without breaking anything. Doing so will update the version numbers specified in the ​front of each package, hence updating the project's package. json file.


4 Answers

Yes there is an option :

npm outdated

This will list modules, with available updates. It supports syntax for specifying the module name.

According to the Documentation, the syntax is

npm outdated [<name> [<name> ...]]

This gives you to specify the module name you wish to check exclusively, like

$ npm outdated mongoose

Note

To use this properly, you'll have to add a version number of the target module(s) with range greater than or greater than or equal. You can check node-semver, which is integrated into npm to check the syntax.

Example

{
    "dependencies": {
        "express": "3.2.0",
        "mongoose": ">= 3.5.6",
    },
}

Will give the following result ( since today the latest mongoose version is 3.6.9 )

$ npm outdated
...
[email protected] node_modules/mongoose current=3.6.7
$

While if you place

{
    "dependencies": {
        "express": ">= 3.2.0",
        "mongoose": ">= 3.5.6",
    },
}

The result will be :

$ npm outdated
...
[email protected] node_modules/mongoose current=3.6.7
[email protected] node_modules/express current=3.2.0
$
like image 199
drinchev Avatar answered Sep 28 '22 03:09

drinchev


there's a service like travis that checks it automatically:

https://gemnasium.com

like image 43
Jonathan Ong Avatar answered Sep 28 '22 04:09

Jonathan Ong


you need to do that manually using the update command:

$ npm update

you can also change the version:

"nodemailer": "*" // this would use the newest version

or

"nodemailer": ">=0.4.0" // this will install any version which is at least 0.4.0

and so on....

read more about that here: https://npmjs.org/doc/json.html#dependencies

EDIT: there is some possibility if the module is available via github. you can then "watch" that repo, and get notification updates!

like image 38
hereandnow78 Avatar answered Sep 28 '22 02:09

hereandnow78


You might want to check out https://david-dm.org/ as it is free service that does the check. This is more target at adding a build badge to your README, but the details it gives on the page are quite helpful.

See https://david-dm.org/jshint/jshint as an example output.

like image 34
nschonni Avatar answered Sep 28 '22 02:09

nschonni