<?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: Satej</title>
    <description>The latest articles on DEV Community by Satej (@s3cube).</description>
    <link>https://dev.to/s3cube</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%2F257526%2F7c9d5524-c5ce-4cb2-a8f1-9423c4b3f963.JPG</url>
      <title>DEV Community: Satej</title>
      <link>https://dev.to/s3cube</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/s3cube"/>
    <language>en</language>
    <item>
      <title>Git-ting it Right : Best Practices for your Git Repository</title>
      <dc:creator>Satej</dc:creator>
      <pubDate>Sat, 27 Jun 2020 17:31:23 +0000</pubDate>
      <link>https://dev.to/s3cube/git-ting-it-right-best-practices-for-your-git-repository-9jc</link>
      <guid>https://dev.to/s3cube/git-ting-it-right-best-practices-for-your-git-repository-9jc</guid>
      <description>&lt;p&gt;Over the years, I've worked on multiple software development projects, consisting of anywhere from 2 to over 30+ active software developers working on the same repository. It takes very little time to go from wonderfully written code to an absolute wreckage - both in terms of your code base and your repository.&lt;/p&gt;

&lt;p&gt;In this article, I dive into some git best practices that I've learned on the job and actively use while working. I expect this list to grow and I'll add those points as and when I can.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Use multiple branches
&lt;/h2&gt;

&lt;p&gt;There are few very reasons to exclusively use the main branch. Let's see what they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're the only developer working on a repository&lt;/li&gt;
&lt;li&gt;You love chaos&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The solution to avoiding absolute anarchy is pretty easy - use other branches.&lt;/p&gt;

&lt;p&gt;Many organizations create the following branches apart from the ones mentioned in the Point #2:&lt;/p&gt;

&lt;h4&gt;
  
  
  Main
&lt;/h4&gt;

&lt;p&gt;The Main branch typically contains your code that is safe to deploy to production. You would ideally never commit directly to this branch, and code is to be only added via pull-requests here.&lt;/p&gt;

&lt;h4&gt;
  
  
  Development or Dev
&lt;/h4&gt;

&lt;p&gt;This branch is where code that is being actively developed and worked on would reside. It may have some bugs that are being fixed. If you're working on a feature, you'd ideally create a new feature branch(more on this below) from the development branch, and merge this back into the development branch.&lt;/p&gt;

&lt;h4&gt;
  
  
  Production and Pre-Production
&lt;/h4&gt;

&lt;p&gt;Larger companies may have a separate Production and Pre-Production/Staging branch to release their code onto internal or public networks. These are typically hooked up to plugins that automatically deploy your code when a new commit is made. &lt;/p&gt;

&lt;h4&gt;
  
  
  Test
&lt;/h4&gt;

&lt;p&gt;Similarly, the Test branch may be used for releases onto a test network or test devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Follow a Branch Naming Convention ( and stick to it )
&lt;/h2&gt;

&lt;p&gt;As your product grows, you're going to want to add new features and in the process fix bugs in your code. Some of these bugs will have your team on their toes. &lt;/p&gt;

&lt;p&gt;It's important to distinguish what kind of code you're merging into your working branch, primarily to allow you to track changes in the future. This is where branch naming conventions help.&lt;/p&gt;

&lt;p&gt;I typically use these three the most, but I've also seen some teams use the test branch for any QA or review related purposes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Feature Branches
&lt;/h4&gt;

&lt;p&gt;Let's say you're working on a sparkling new feature to allow users to save a post they see on their feed. You can name your branch along the lines of :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;feature/save-post-from-feed
feature/save-newsfeed-post
feature/what-does-the-feature-do
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While there's nothing stopping you, I'd refrain from naming it along the lines of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;feature/allowtheusertosaveapostfromthenewseed
feature/ALLOWTHEUSERTOSAVEPOST
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using just verbs with hyphens helps easily read and understand the task being carried out.&lt;/p&gt;

&lt;h4&gt;
  
  
  BugFix Branches
&lt;/h4&gt;

&lt;p&gt;Let's say you're fixing a bug that isn't extremely crtical. The feature you built to save a post has an issue with the button and you're working on a fix.  With Bugfixes, I personally like to reference the issue number on the repository to see a detailed explanation of what is being fixed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bugfix/button-change-for-save-post-#388
bugfix/save-post-#388
bugfix/what-does-it-fix
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Don't forget to write in the pull-request, what your fix does.&lt;/p&gt;

&lt;h4&gt;
  
  
  HotFix Branches
&lt;/h4&gt;

&lt;p&gt;Finally, for those fixes that are absolutely critical in terms of their severity and need to be fixed immediately, you would use the hotfix branches.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hotfix/allow-admin-facebook-login-#392
hotfix/what-does-it-fix
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using these distinctions allows for some traceability when working on a larger code base.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Write Commit Messages (or atleast try)
&lt;/h2&gt;

&lt;p&gt;Okay, we've all been guilty of this. Especially when it is 3am, and you honestly don't care what the commit message says. Don't forget to add a commit message that covers the important information. Here's a sample&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Moved chartData from Statistics.js to Redux Chart State"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also link issues to pull requests with your commit message. I'd highly recommend this link on &lt;a href="https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword"&gt;linking a pull request to issues&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Use Commit Hooks
&lt;/h2&gt;

&lt;p&gt;If you aren't familiar with what commit hooks are, that's not a problem. Think of them as scripts that run before, during or after you perform any function with git. &lt;/p&gt;

&lt;p&gt;There are a couple of use-cases for running commit hooks&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to automatically indent your code before a commit is made&lt;/li&gt;
&lt;li&gt;You want to check for code quality before a pull request is made&lt;/li&gt;
&lt;li&gt;You want to send an email after a pull request is made&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I personally use pre-commit hooks the most to automatically format and indent my code with a lot of help from &lt;a href="https://www.npmjs.com/package/husky"&gt;husky&lt;/a&gt;. If you'd like to learn more about commit hooks, I'd recommend checking out &lt;a href="https://githooks.com/"&gt;Git Hooks&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Automate your Deployment
&lt;/h2&gt;

&lt;p&gt;Continuous Integration/Continous Delivery(CI/CD) is a topic in itself, but setting up a workflow that let's you write code and at the push of a button deploys to a server of your choice is an incredible feeling. &lt;/p&gt;

&lt;p&gt;For my &lt;a href="https://satejsawant.dev/"&gt;personal website&lt;/a&gt;, I use &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; to automatically build my website the moment a new commit is pushed to my Main branch. All Netlify requires is access to your repository and a few more instructions regarding which build command to run and what directory to serve from. For larger projects, you definitely want to check out &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; and a tool like &lt;a href="https://travis-ci.org/"&gt;TravisCI&lt;/a&gt; or &lt;a href="https://circleci.com"&gt;CirleCI&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;And that's about it!&lt;/p&gt;

&lt;p&gt;Did you like this article? Let me know on &lt;a href="https://twitter.com/SatejSawant"&gt;Twitter&lt;/a&gt; at &lt;a href="https://twitter.com/SatejSawant"&gt;@SatejSawant&lt;/a&gt;. If you spot something incorrect, please write to me at satejs93[at]gmail[dot]com. You can also find me on &lt;a href="https://www.linkedin.com/in/satejsawant"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>NPM Audit Fix: The Complete Guide to How It Works - Part 2</title>
      <dc:creator>Satej</dc:creator>
      <pubDate>Tue, 09 Jun 2020 20:12:42 +0000</pubDate>
      <link>https://dev.to/s3cube/npm-audit-fix-the-complete-guide-to-how-it-works-part-2-4opk</link>
      <guid>https://dev.to/s3cube/npm-audit-fix-the-complete-guide-to-how-it-works-part-2-4opk</guid>
      <description>&lt;p&gt;In my earlier post, I dived into &lt;a href="https://dev.to/s3cube/npm-audit-a-complete-guide-to-how-it-works-under-the-hood-part-1-56dg"&gt;how NPM Audit works&lt;/a&gt;. In this concluding post, I talk specifically about how the fix flag works in &lt;code&gt;npm audit fix&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To do a quick re-cap if you haven't read the &lt;a href="https://dev.to/s3cube/npm-audit-a-complete-guide-to-how-it-works-under-the-hood-part-1-56dg"&gt;earlier article&lt;/a&gt;, NPM will use your &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt; files to create an object consisting of your dependencies. These dependencies are then sent over to your registry(typically NPM) to check for any reported vulnerabilities. Once it receives a response from the registry, NPM begins the process of fixing those vulnerabilities.&lt;/p&gt;

&lt;p&gt;The response from NPM outlines the actions to be taken regarding vulnerabilities in your dependencies. The response body looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;actions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;isMajor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;action&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;install&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resolves&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1486&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;optional&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bundled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;target&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.18.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There may (and probably will) be multiple objects in this actions object returned from the registry.&lt;/p&gt;

&lt;p&gt;The first job for NPM is to segregate these individual objects based on their importance and type. It uses a reducer for this, and begins with the object below as the original value. If you aren't very familiar with reducers, check out this Mozilla Developer Network(MDN) link on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;how the reduce function works in Javascript&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;install&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;installFixes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;updateFixes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;major&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;majorFixes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;review&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Alright, so how exactly does audit.js act on this actions array?
&lt;/h4&gt;

&lt;p&gt;To begin with, the actions array seen in the previous snippet is run through a reducer.&lt;/p&gt;

&lt;p&gt;In this reducer, each action is passed to a filter function called &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/audit.js#L133"&gt;filterEnv&lt;/a&gt;. This function returns a new object with only the relevant dependencies. The relevant dependencies are identified basis the environment you're building in - essentially dev and production.&lt;/p&gt;

&lt;p&gt;There are four buckets a fix may fall into&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;install&lt;/li&gt;
&lt;li&gt;update&lt;/li&gt;
&lt;li&gt;major&lt;/li&gt;
&lt;li&gt;review&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the &lt;code&gt;isMajor&lt;/code&gt; field and the &lt;code&gt;action&lt;/code&gt; field seen in each of the objects from  the sample response body above, the sets seen earlier are populated. Depending on the set, information regarding the module, target, id and path of the vulnerability fix is added. You can see this in the &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/audit.js#L217"&gt;npm audit.js file&lt;/a&gt; here.&lt;/p&gt;

&lt;p&gt;Since the sample response is of action type install, the &lt;code&gt;install&lt;/code&gt; Set would be populated with the module and target. It would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="mf"&gt;1.18&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Meanwhile, the &lt;code&gt;installFixes&lt;/code&gt; Set would be populated with the id and path. It would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1486&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Similarly, the other sets are also filled depending on the type of vulnerability you're dealing with.&lt;/p&gt;

&lt;p&gt;Finally, NPM will install these dependencies by passing the contents of these sets to an instance of the &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/audit.js#L58%7D"&gt;Auditor Class&lt;/a&gt; which extends the &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/node_modules/libcipm/index.js#L41"&gt;Installer Class&lt;/a&gt;. The &lt;code&gt;run()&lt;/code&gt; method is called on this instance which actually runs the installation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Does NPM Audit Fix handle every vulnerability?
&lt;/h4&gt;

&lt;p&gt;Nope. If a particular object has the action key with value &lt;code&gt;review&lt;/code&gt;, it is added to the review set. These items require manual review by the developer and are not updated automatically.&lt;/p&gt;

&lt;h4&gt;
  
  
  But, I heard about a --force flag?
&lt;/h4&gt;

&lt;p&gt;Correct! But that's primarily for what are considered as "major changes". &lt;/p&gt;

&lt;p&gt;You can identify if a change is a major one through the &lt;code&gt;isMajor&lt;/code&gt; flag. These are essentially actions that that involve potentially breaking changes. If the &lt;code&gt;--force&lt;/code&gt; flag is provided, NPM will go ahead and fix the vulnerability - albeit with the inherent risk that something may break.&lt;/p&gt;

&lt;p&gt;For other cases where the flag is not specified, NPM will produce a log asking you to fix these manually or use &lt;code&gt;npm audit fix --force&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I referred to a couple of resources while writing this article. Here they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/npm/cli/blob/latest/lib/audit.js"&gt;https://github.com/npm/cli/blob/latest/lib/audit.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/npm-audit-report"&gt;https://www.npmjs.com/package/npm-audit-report&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Did you like this article? Let me know on &lt;a href="https://twitter.com/SatejSawant"&gt;Twitter&lt;/a&gt; at &lt;a href="https://twitter.com/SatejSawant"&gt;@SatejSawant&lt;/a&gt;. If you spot something incorrect, please write to me at satejs93[at]gmail[dot]com. You can also find me on &lt;a href="https://www.linkedin.com/in/satejsawant"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>javascript</category>
    </item>
    <item>
      <title>NPM Audit: A Complete Guide to How It Works - Part 1</title>
      <dc:creator>Satej</dc:creator>
      <pubDate>Fri, 29 May 2020 20:28:17 +0000</pubDate>
      <link>https://dev.to/s3cube/npm-audit-a-complete-guide-to-how-it-works-under-the-hood-part-1-56dg</link>
      <guid>https://dev.to/s3cube/npm-audit-a-complete-guide-to-how-it-works-under-the-hood-part-1-56dg</guid>
      <description>&lt;p&gt;Recently, I began working with a research lab to help them with their front-end architecture. In the process of refactoring their build process, I came across this message almost half a dozen times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;found&lt;/span&gt; &lt;span class="mi"&gt;611&lt;/span&gt; &lt;span class="nx"&gt;vulnerabilities&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt; &lt;span class="nx"&gt;low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="nx"&gt;moderate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="nx"&gt;high&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="s2"&gt;`npm audit fix`&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;fix&lt;/span&gt; &lt;span class="nx"&gt;them&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;`npm audit`&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;details&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That number of vulnerabilities was initially over 15,000 and after running &lt;code&gt;npm audit&lt;/code&gt; and &lt;code&gt;npm audit fix&lt;/code&gt; a couple of times, I had a sense of accomplishment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l41Ye5dhLPqILtT2w/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l41Ye5dhLPqILtT2w/giphy.gif" alt="I did it!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  But, what exactly did I do?
&lt;/h4&gt;

&lt;p&gt;In this two part article, I dive into exactly that. This article helps you understand how &lt;code&gt;npm audit&lt;/code&gt; works, while Part 2 wraps it up with what the &lt;code&gt;--fix&lt;/code&gt; flag specifically does. So let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  NPM AUDIT
&lt;/h2&gt;

&lt;p&gt;If you have never heard of the command before, &lt;code&gt;npm audit&lt;/code&gt; helps you find (and fix) security vulnerabilities in your project's dependency tree.&lt;/p&gt;

&lt;p&gt;To begin with, npm audit, needs two files to be present - &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Without those, you'll run into either of the two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;ERR&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;EAUDITNOPJSON&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;ERR&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;audit&lt;/span&gt; &lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="kr"&gt;package&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="nx"&gt;found&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cannot&lt;/span&gt; &lt;span class="nx"&gt;audit&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="nx"&gt;without&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="kr"&gt;package&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;ERR&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;EAUDITNOLOCK&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;ERR&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;audit&lt;/span&gt; &lt;span class="nx"&gt;Neither&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;shrinkwrap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="nx"&gt;nor&lt;/span&gt; &lt;span class="kr"&gt;package&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="nx"&gt;found&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cannot&lt;/span&gt; &lt;span class="nx"&gt;audit&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="nx"&gt;without&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;lockfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you don't know how to create a package-lock.json file, you can run this command :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="kr"&gt;package&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;only&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  So why does it need these two files?
&lt;/h4&gt;

&lt;p&gt;NPM fetches the dependencies and dev dependencies by reading both these files. In the absence of the package-lock.json file, it uses the &lt;a href="https://docs.npmjs.com/cli/shrinkwrap"&gt;npm-shrinkwrap.json&lt;/a&gt; file.It also uses the shrinkwrap file if both of the files are present. If you want to see exactly how this is done, here is a link to the &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/audit.js#L157"&gt;audit.js file&lt;/a&gt; in the NPM repository. The dependencies from the package-json file and the contents of the package-lock file are passed to a function called &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/install/audit.js#L122"&gt;audit.generate()&lt;/a&gt; in the form of parameters called require and sw.&lt;/p&gt;

&lt;h4&gt;
  
  
  Okay, what next?
&lt;/h4&gt;

&lt;p&gt;In the generate function, a deep clone of the shrinkwrap(or package-lock) file is created. After passing the inputs through a series of functions to scrub and sanitize the data, an object is created containing two keys, namely &lt;code&gt;requires&lt;/code&gt; and &lt;code&gt;dependencies&lt;/code&gt;. You can checkout the code on &lt;a href="https://github.com/npm/cli/blob/abdf52879fcf0e0f534ad977931f6935f5d1dce3/lib/install/audit.js#L140"&gt;how the data is scrubbed here&lt;/a&gt;. The require and dependencies keys enumerate the packages required in the project along with their version, integrity(the hash) and more information.&lt;/p&gt;

&lt;p&gt;Once it has made this object, npm calls the &lt;code&gt;audit.submitForFullReport(auditReport)&lt;/code&gt; function. This makes a POST request to &lt;code&gt;https://registry.npmjs.org/-/npm/v1/security/audits&lt;/code&gt; with this JSON object as the body. NPM Audit uses the &lt;a href="https://www.npmjs.com/package/npm-registry-fetch"&gt;npm-registry-fetch package&lt;/a&gt; for this.&lt;/p&gt;

&lt;p&gt;Here is a sample request body of the data sent across:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;package-name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.0.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;requires&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.18.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dependencies&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.18.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The response of this API call returns detailed information on any reported warnings and vulnerabilities contained in your repository after checking them with your registry. In most cases, this registry is NPM.&lt;/p&gt;

&lt;p&gt;Below, you will see a sample response for the request body from above. We see a sample vulnerability in &lt;a href="https://www.npmjs.com/package/http-proxy"&gt;http-proxy&lt;/a&gt;. Each such object contains information about who it was reported by, the relevant dates and more about the finding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1486&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;findings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.18.0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paths&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                    &lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1486&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;created&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2020-02-21T14:16:24.023Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;updated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2020-05-18T14:50:08.944Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;deleted&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Denial of Service&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;found_by&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://twitter.com/_awry&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Grant Murphy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;reported_by&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://twitter.com/_awry&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Grant Murphy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module_name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http-proxy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cves&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vulnerable_versions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;1.18.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;patched_versions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;gt;=1.18.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;overview&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Versions of `http-proxy` prior to 1.18.1 are vulnerable to Denial of Service. An HTTP request with a long body triggers an `ERR_HTTP_HEADERS_SENT` unhandled exception that crashes the proxy server. This is only possible when the proxy server sets headers in the proxy request using the `proxyReq.setHeader` function.   &lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;For a proxy server running on `http://localhost:3000`, the following curl request triggers the unhandled exception:  &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;```

curl -XPOST http://localhost:3000 -d &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$(python -c 'print(&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;x&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*1025)')&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;

```&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;recommendation&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Upgrade to version 1.18.1 or later&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;references&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;- [Patch PR](https://github.com/http-party/node-http-proxy/pull/1447/files)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;access&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;severity&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cwe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CWE-400&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;metadata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exploitability&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;affected_components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;url&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://npmjs.com/advisories/1486&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, after collating all this information and grouping the issues based on their seriousness, NPM typically calls &lt;code&gt;audit.printFullReport(auditResult)&lt;/code&gt; which prints the report as you see it on the screen. To do this, NPM uses a package called the &lt;a href="https://www.npmjs.com/package/npm-audit-report"&gt;npm audit report&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;And that's how you see the outfit that you're familiar with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ &amp;gt;=0.2.1 &amp;lt;1.0.0 || &amp;gt;=1.2.3                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ react-scripts                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ react-scripts &amp;gt; jest &amp;gt; jest-cli &amp;gt; jest-config &amp;gt; babel-jest &amp;gt; │
│               │ @jest/transform &amp;gt; jest-haste-map &amp;gt; fsevents &amp;gt; node-pre-gyp &amp;gt; │
│               │ rc &amp;gt; minimist                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1179                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In Part 2 of this article, I dive into how the &lt;code&gt;--fix&lt;/code&gt; flag works. Adding a link soon!&lt;/p&gt;

&lt;p&gt;Did you like this article? Let me know on &lt;a href="https://twitter.com/SatejSawant"&gt;Twitter&lt;/a&gt; at &lt;a href="https://twitter.com/SatejSawant"&gt;@SatejSawant&lt;/a&gt;. If you spot something incorrect, please write to me at satejs93[at]gmail[dot]com.&lt;/p&gt;

&lt;p&gt;I referred to a couple of resources while writing this article. Here they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/npm/cli/blob/latest/lib/audit.js"&gt;https://github.com/npm/cli/blob/latest/lib/audit.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/npm-audit-report"&gt;https://www.npmjs.com/package/npm-audit-report&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gyanblog.com/gyan/how-node-npm-audit-rest-api-vulnerability/"&gt;https://www.gyanblog.com/gyan/how-node-npm-audit-rest-api-vulnerability/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3resource.com/npm/how-to-run-a-security-audit-with-npm-audit.php"&gt;https://www.w3resource.com/npm/how-to-run-a-security-audit-with-npm-audit.php&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Part 2 of this article, refer to &lt;a href="https://dev.to/s3cube/npm-audit-fix-the-complete-guide-to-how-it-works-part-2-4opk"&gt;this link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
    </item>
    <item>
      <title>Deno? Do you mean Node?</title>
      <dc:creator>Satej</dc:creator>
      <pubDate>Fri, 15 May 2020 19:01:23 +0000</pubDate>
      <link>https://dev.to/s3cube/deno-do-you-mean-node-36pg</link>
      <guid>https://dev.to/s3cube/deno-do-you-mean-node-36pg</guid>
      <description>&lt;p&gt;The last couple of days, I've come across a lot of my favourite tweeple talking about Deno. &lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZgME7jFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1138547910524588034/4R6jdBch_normal.png" alt="Tyler McGinnis profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Tyler McGinnis
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/tylermcginnis"&gt;@tylermcginnis&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52oNvK_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-ff4bdab814039c4cb172a35ea369e0ea9c6a4b59b631a293896ae195fa26a99d.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Is it pronounced Deno or Deno?
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      22:48 PM - 14 May 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1261065756034228224" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1261065756034228224" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      22
      &lt;a href="https://twitter.com/intent/like?tweet_id=1261065756034228224" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      252
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;
 

&lt;p&gt;Having just recently re-entered the JavaScript universe after almost a year of Java, I was like wait a second.&lt;br&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/h4Z6RfuQycdiM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/h4Z6RfuQycdiM/giphy.gif" alt="Confused GIF"&gt;&lt;/a&gt;&lt;/p&gt;
 Are you guys talking about Node? 



&lt;p&gt;A few google searches later, I came to realize that that the JavaScript universe had given birth to it's newest creation - &lt;a href="https://deno.land/"&gt;Deno&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xd8AtgDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://raw.githubusercontent.com/denolib/animated-deno-logo/master/deno-rect-24fps.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xd8AtgDR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://raw.githubusercontent.com/denolib/animated-deno-logo/master/deno-rect-24fps.gif" alt="Deno the Dino"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So why is everyone on the internet suddenly talking about this cute little dinosaur in the rain?&lt;/p&gt;

&lt;p&gt;Earlier this week, the team at Deno, dropped its first stable release, &lt;a href="https://deno.land/v1"&gt;Deno v1.0&lt;/a&gt;. It's got a lot of cool features, and people are really excited to see if this will "kill" Node.&lt;/p&gt;
&lt;h3&gt;
  
  
  But there's nothing wrong with Node?
&lt;/h3&gt;

&lt;p&gt;Well, that's partly what I thought too, until I saw Ryan Dahl's(he created Node) talk at JSConf EU from 2018 and came across a couple other articles such as  &lt;a href="https://blog.risingstack.com/why-developers-love-node-js-2018-survey/"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In his talk, Ryan speaks about 10 things that he regrets building into Node. I've elaborated more on what I consider the most important from those ten, but definitely check out the video below.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/M3BM9TB-8yA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h5&gt;
  
  
  Security
&lt;/h5&gt;

&lt;p&gt;While V8 is a secure sandbox, in some situations, there's no reason for certain applications to have access to the file system or the network. Access to these entities should be restricted and access-controlled. Ryan's example of a linter not needing access to the underlying system perfectly encapsulates this.&lt;/p&gt;

&lt;h5&gt;
  
  
  Promises
&lt;/h5&gt;

&lt;p&gt;Promises were initially added in June 2009, but later removed in February 2010 from Node -  in an effort to remain minimal and do away with the overhead they introduced of an extra object into every callback. While this move allowed the eco-system to develop Promises as we know them today, Dahl attributes the problem with the "current aging async APIs" to not sticking with promises initially.   &lt;/p&gt;

&lt;h5&gt;
  
  
  Package.json
&lt;/h5&gt;

&lt;p&gt;This file has become the heart of pretty much every node project. The original idea apparently wasn't really to have a directory of files that package.json has become. This is made worse by the fact that npm has become a private centralized source of these packages. Coupled along with the "unnecessary" information about the package name, license,etc - things could be better.&lt;/p&gt;

&lt;h5&gt;
  
  
  Node Modules
&lt;/h5&gt;

&lt;p&gt;Dahl believes having &lt;code&gt;node_modules&lt;/code&gt; massively complicates the module resolution algorithm. There were simpler ways to do this. I like this particular article that elaborates a bit on the topic of &lt;a href="https://www.freecodecamp.org/news/requiring-modules-in-node-js-everything-you-need-to-know-e7fbd119be8/"&gt;module resolution&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a disclaimer, this talk is from 2018, and I'm sure things have changed ever since. I do understand that fundamental issues regarding native TypeScript support and security remain.&lt;/p&gt;

&lt;p&gt;While these issues exist, due to the large number of users that Node has, it is massively difficult to bring about sweeping changes in the current system.&lt;/p&gt;

&lt;p&gt;Thus, Deno.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, what is Deno?
&lt;/h3&gt;

&lt;p&gt;Deno is a new runtime for executing JavaScript and TypeScript outside of the web browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  And how is it different from Node again?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Security
&lt;/h4&gt;

&lt;p&gt;To begin with, the code is executed in a secure sandbox, just like it would be on a browser. Your code cannot access the hard drive, open network connections without your permission. It always requires &lt;strong&gt;&lt;em&gt;explicit permission&lt;/em&gt;&lt;/strong&gt; for file, network and environment access. It has built in flags for this such as &lt;code&gt;--allow-net&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  First Class TypeScript Support
&lt;/h4&gt;

&lt;p&gt;One of the most painful issues I've come across while working with JavaScript is the lack of type-checking built in. TypeScript supports that, and so does Deno. All of Deno's standard modules are written in TypeScript.&lt;/p&gt;

&lt;h4&gt;
  
  
  Promises
&lt;/h4&gt;

&lt;p&gt;In Deno, the lowest level binding layer to the system, called "ops" are tied to promises. All callbacks in Deno thus, arise from promises.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rust APIs
&lt;/h4&gt;

&lt;p&gt;Deno internally is a collection of Rust modules that are integrated at different layers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Package Management
&lt;/h4&gt;

&lt;p&gt;Deno doesn't use NPM. Yeah. Wow. It directly references URLs or file paths. Oh, it also does not use &lt;code&gt;package.json&lt;/code&gt; in its module resolution algorithm. &lt;/p&gt;

&lt;h4&gt;
  
  
  Caching
&lt;/h4&gt;

&lt;p&gt;Code that is remote is cached on the first execution, and not updated till you explicitly ask for it to be reloaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  TDLR?
&lt;/h3&gt;

&lt;p&gt;Deno definitely seems promising. It's simplicity is definitely a step up from Node, but only its adoption over a longer time will really tell. &lt;/p&gt;

&lt;p&gt;The one tweet that really stood out to me, is this one:&lt;br&gt;
&lt;/p&gt;
&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--3n44cp2d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/282339703/Photo_7_normal.jpg" alt="Bradley Farias profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Bradley Farias
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @bradleymeck
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52oNvK_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-ff4bdab814039c4cb172a35ea369e0ea9c6a4b59b631a293896ae195fa26a99d.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Most exciting thing about Deno? Node getting a competitor. Competition is a way to bring progress by showing innovation and allowing evolution beyond the initial shock.
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      23:01 PM - 13 May 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1260706881791819778" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1260706881791819778" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      24
      &lt;a href="https://twitter.com/intent/like?tweet_id=1260706881791819778" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      308
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;I'm really excited to see how Node steps up to the competition now.&lt;/p&gt;

&lt;p&gt;Are you planning on trying out Deno? Let me know in the comments what you're building with it!&lt;/p&gt;

</description>
      <category>deno</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
