Impress your colleagues with these NPM tricks
Tags: beginners, javascript, node
Published: 2019-05-13 22:20:35

---
title: Impress your colleagues with these NPM tricks
published: true
description: 
tags: #beginner #javascript #nodejs
---

<!-- wp:heading {"level":1} -->
<h1></h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Just like anyone else, developers enjoy knowing some little tricks to show to their colleagues or friends. Today, I have decided to write about some of these keyboard magic that you can use when working with the Node Package Manager (<strong>NPM</strong>). These won’t only impress you and the people around you, but will also make your workflow definitely faster and more concise. So now that we made this little premise, let’s start to analyze these tricks!&nbsp;<br></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="mce_3">#1 Package initialization</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Do you want to quickly initialize a new package? Are you tired of those infinite system questions that appear when doing so? Then <strong>run npm init-</strong>y or <strong>npm init-f.</strong>These commands will allow you to skip those questions and jump straight into your next amazing project!<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427003402_carbon+15.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":1} -->
<h1></h1>
<!-- /wp:heading -->

<!-- wp:heading -->
<h2 id="mce_5">#2 Opening a package’s homepage</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Are you working with a cool npm package you just discovered? Do you want to check its homepage to read the documentation? Then run <strong>npm home“your-package”.</strong>This command will bring you <strong>directly to the page</strong> you were looking for!<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427086472_carbon+18.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#3 Opening a package’s GitHub Repository</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Similarly to the command described above, running <strong>npm repo</strong><strong>“your-package”</strong> will take you directly to a webpage. But this time, you will get automatically redirected to the<strong> package official GitHub repository.&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427071623_carbon+17.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#4 List all the installed packages</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Why should we waste our time by opening the <strong>package.json </strong>file to check what packages we have installed? Simply run <strong>npm ls - - depth 0 </strong>and you will get the informations you were looking for.&nbsp;<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427205386_carbon+19.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#5 List the available scripts</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>New project new scripts right? but again, having to go through the <strong>package.json </strong>file can be tedious and time-consuming. Let’s get this list by running the <strong>npm run </strong>command instead!<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427307018_carbon+20.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#6 Check packages that are not declared in package.json</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Another useful command, use <strong>npm prune </strong>for performing this operation. This command will run through your <strong>package.json </strong>file and compare its content with the <strong>/node_modules</strong> content. You will receive as an output a list of all those packages that are not in the <strong>package.json </strong>file. After doing this, <strong>npm prune </strong>will remove those packages together with those which you haven’t added manually to <strong>package.json</strong> or that were<strong> npm install</strong>ed without the <strong>-</strong><strong>-save</strong> flag.&nbsp;<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427786666_carbon+28.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#7 Bump a package version</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Need to bump a package? Simply run <strong>npm </strong>together with <strong>minor/major/patch </strong>command.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427412393_carbon+21.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>#8 Running a test</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You are probably already running the <strong>npm run test </strong>command many times a day right? but why not using the shorter version <strong>npm t </strong>which is exactly the same!<br></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427466097_carbon+22.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":1} -->
<h1>Bonus commands</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Still hungry for some more npm useful command shortcuts? Then check out this bonus list I have prepared for you.&nbsp;<br></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Package installation</h2>
<!-- /wp:heading -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427663717_carbon+25.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Global package installation</h2>
<!-- /wp:heading -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427620976_carbon+24.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Package installation + saving as a dev dependency&nbsp;</h2>
<!-- /wp:heading -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427734993_carbon+27.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Package installation + saving as a dependency </h2>
<!-- /wp:heading -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://d2mxuefqeaa7sj.cloudfront.net/s_B55F67F05B8C352284B6DC7858640513965665824D642D96BB9E833CD76825D6_1552427699826_carbon+26.png" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Conclusion</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Being able to impress your colleagues is great, but leaving this article being aware of all the tricks you can learn when working with a technology is even better. Hope this article helped you to discover some tricks you didn’t know about before reading it and that it inspired you to go deeper when learning something new!<br></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To be up-to-date with content like this, don't forget to stay tuned with my blog: <a href="https://thecoderswag.com/">TheCoderSwag.com</a></p>
<!-- /wp:paragraph -->