{"id":1526,"date":"2015-12-30T08:20:45","date_gmt":"2015-12-30T08:20:45","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1526"},"modified":"2015-12-30T08:25:11","modified_gmt":"2015-12-30T08:25:11","slug":"check-outdated-packages-via-npm","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/javascript\/nodejs\/check-outdated-packages-via-npm\/","title":{"rendered":"How to check for outdated packages via npm"},"content":{"rendered":"<p>In this post I&#8217;ll show you the modules which help in finding the outdated packages via npm. This is an excerpt from the book <a href=\"http:\/\/amzn.to\/1Ug3kBr\">Deploying Node.js by Sandro Pasquali<\/a>. I was a technical reviewer for this book and you can read <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/books\/programming\/technical-review-of-the-deploying-node-js-book-by-sandro-pasquali\/\">my review here<\/a>.<\/p>\n<p>This command will list <strong>globally installed<\/strong> packages:<\/p>\n<pre class=\"lang:default decode:true\">npm root -g<\/pre>\n<p>&nbsp;<\/p>\n<p>This following command will give a full list of other dependencies in a tree list:<\/p>\n<pre class=\"lang:default decode:true\">npm list --global<\/pre>\n<p>There are also some aliases to this command like <em>ls<\/em>, <em>la<\/em>. You can learn more about it from the <a href=\"https:\/\/docs.npmjs.com\/cli\/ls\">official documentation<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>This command will list <strong>outdated<\/strong>\u00a0packages:<\/p>\n<pre class=\"lang:default decode:true\">npm outdated<\/pre>\n<p>&nbsp;<\/p>\n<p>A very useful global tool for performing these sorts of checks is <a href=\"https:\/\/github.com\/dylang\/npm-check\">npm-check<\/a>, which delivers more detailed information. \u00a0You can install it with <span class=\"lang:default decode:true crayon-inline \">npm install npm-check<\/span>\u00a0\u00a0and run it simply by\u00a0running <span class=\"lang:default decode:true crayon-inline\">npm-check<\/span>. It tells you what modules are out of date and provides a link to the package&#8217;s documentation so you can decide if you want the update.<\/p>\n<p>&nbsp;<\/p>\n<p>To remove packages that are installed but no longer listed in <strong>package.json<\/strong>\u00a0file you can use the command <span class=\"lang:default decode:true crayon-inline\">npm prune<\/span>. Note that this is simply a technique for cleaning up the node_modules folder within an <strong>individual<\/strong> package\u2019s folder; it is not a smart, global tool for removing unused packages across the entire tree.<\/p>\n<p>&nbsp;<\/p>\n<p>The <a href=\"https:\/\/www.npmjs.com\/package\/dependency-check\">dependency-check module<\/a> is a great tool for finding unnecessary packages. Once you install it you run it like this:<\/p>\n<pre class=\"lang:default decode:true \">dependency-check package.json --unused<\/pre>\n<p>and, if some\u00a0modules aren&#8217;t used you&#8217;ll get a message like:<\/p>\n<pre class=\"lang:default decode:true \">Fail! Modules in package.json not used in code: express<\/pre>\n<p><em>The entry point to your application has to be listed in package.json, as dependency-check needs to know the root of your application.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The <a href=\"https:\/\/docs.npmjs.com\/cli\/dedupe\">npm dedupe<\/a>\u00a0module attempts to reduce the number of redundant package installs, \u201cflattening\u201d the tree, and therefore reducing install time.<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"550\">\n<p lang=\"en\" dir=\"ltr\">How to check for <a href=\"https:\/\/twitter.com\/hashtag\/outdated?src=hash\">#outdated<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/packages?src=hash\">#packages<\/a> via <a href=\"https:\/\/twitter.com\/hashtag\/npm?src=hash\">#npm<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/nodejs?src=hash\">#nodejs<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/node?src=hash\">#node<\/a>.js <a href=\"https:\/\/t.co\/bNJ8aiGBmm\">https:\/\/t.co\/bNJ8aiGBmm<\/a><\/p>\n<p>&mdash; Nikola Bre\u017enjak (@HitmanHR) <a href=\"https:\/\/twitter.com\/HitmanHR\/status\/682114869185875968\">December 30, 2015<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll show you the modules which help in finding the outdated packages via npm. This is an excerpt from the book Deploying Node.js by Sandro&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2243,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nodejs"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1526"}],"version-history":[{"count":7,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1526\/revisions"}],"predecessor-version":[{"id":2471,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1526\/revisions\/2471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/2243"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}