<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shaunak</title>
    <description>The latest articles on DEV Community by Shaunak (@jskidding).</description>
    <link>https://dev.to/jskidding</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F998826%2F000715d5-67fc-451e-9aed-4f7175b2688b.jpg</url>
      <title>DEV Community: Shaunak</title>
      <link>https://dev.to/jskidding</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jskidding"/>
    <language>en</language>
    <item>
      <title>Safe and elegant way to update your npm packages quickly</title>
      <dc:creator>Shaunak</dc:creator>
      <pubDate>Fri, 30 Dec 2022 05:14:35 +0000</pubDate>
      <link>https://dev.to/jskidding/safe-and-elegant-way-to-update-your-npm-packages-quickly-5c5a</link>
      <guid>https://dev.to/jskidding/safe-and-elegant-way-to-update-your-npm-packages-quickly-5c5a</guid>
      <description>&lt;p&gt;Maintaining projects that run on npm brings more trouble than building a new one. Throughout the project development, we refer many external npm packages to help us build faster than reinvent the wheel. Thousands of open-source devs contribute daily to build stable npm packages and make those available to the global dev community.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why should you update npm packages regularly?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Security patches&lt;/p&gt;

&lt;p&gt;Many packages themselves have references to other public npm packages. There are times when a security vulnerability pops up and this needs a chain of updates to the packages, from the source to the destination.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Deprecations&lt;/p&gt;

&lt;p&gt;Methods exposed by these npm packages keep on getting improved and optimized so the developers no longer support old methods.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New features&lt;/p&gt;

&lt;p&gt;Developers keep adding new features to the package. Always good to get the latest.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, the real pain arises when you are building a big project, like Angular, where many external packages like prime-ng, date pickers etc. are being referred. Or you own an old project but still have to maintain the codebase regularly.&lt;/p&gt;

&lt;p&gt;A great tool called NPM Check Updates makes your life easy. It is a CLI that helps safely make those updates with ease.&lt;/p&gt;

&lt;p&gt;Steps to use NPM Check Updates(&lt;code&gt;ncu&lt;/code&gt;)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;code&gt;npm-check-updates&lt;/code&gt;, preferably globally.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;g&lt;/span&gt; &lt;span class="nx"&gt;npm&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;check&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;updates&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;or with &lt;code&gt;npx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;npm&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;check&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;updates&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run NPM Check Updates.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ncu&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This command returns a changelog of all your packages.&lt;br&gt;&lt;br&gt;
Add option &lt;code&gt;-u&lt;/code&gt; to update your &lt;code&gt;package.json&lt;/code&gt; file with the requested versions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are multiple options to get into more details or filter your packages. By semantic versioning (patch, minor, major).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="nx"&gt;patch&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nx"&gt;minor&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nx"&gt;major&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;By name/pattern matching&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// By package name&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;

&lt;span class="c1"&gt;// everything except express&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;reject&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;

&lt;span class="c1"&gt;// pattern matching&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-*&lt;/span&gt;
&lt;span class="nx"&gt;ncu&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;u&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;angular&lt;/span&gt;&lt;span class="cm"&gt;/*
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;npm i&lt;/code&gt; to install the changes&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This two-step process makes wonders, and helps you quickly update your project dependencies. There are many option available to make it safer than manual updates.  &lt;/p&gt;

&lt;p&gt;Some useful &lt;code&gt;ncu&lt;/code&gt; Installation options:&lt;br&gt;&lt;br&gt;
&lt;code&gt;-u, --upgrade&lt;/code&gt; : Overwrite package.json with upgraded versions instead of just logging output to the console.&lt;br&gt;&lt;br&gt;
&lt;code&gt;-f, --filter&lt;/code&gt; : filter by names/string&lt;br&gt;&lt;br&gt;
&lt;code&gt;--cache&lt;/code&gt; : Cache versions to the cache file&lt;br&gt;&lt;br&gt;
&lt;code&gt;--peer&lt;/code&gt; : Checks peer dependencies of the packages and filters updates to compatible versions. Run &lt;code&gt;ncu --help --peer&lt;/code&gt; for more help.&lt;br&gt;&lt;br&gt;
&lt;code&gt;--deep&lt;/code&gt;: Scans current directly recursively for updates.&lt;/p&gt;

&lt;p&gt;For more information refer to their docs:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/npm-check-updates"&gt;https://www.npmjs.com/package/npm-check-updates&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
