<?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: Salifu Sani Rich</title>
    <description>The latest articles on DEV Community by Salifu Sani Rich (@sarscode).</description>
    <link>https://dev.to/sarscode</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%2F236702%2Faecc6062-d49e-434c-bdcf-7bf5915ddf41.jpg</url>
      <title>DEV Community: Salifu Sani Rich</title>
      <link>https://dev.to/sarscode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarscode"/>
    <language>en</language>
    <item>
      <title>npx vs npm - THE npx ADVANTAGE</title>
      <dc:creator>Salifu Sani Rich</dc:creator>
      <pubDate>Sat, 02 Nov 2019 01:41:20 +0000</pubDate>
      <link>https://dev.to/sarscode/npx-vs-npm-the-npx-advantage-1h0o</link>
      <guid>https://dev.to/sarscode/npx-vs-npm-the-npx-advantage-1h0o</guid>
      <description>&lt;p&gt;If you have ever used  &lt;a href="https://nodejs.org"&gt;&lt;strong&gt;node&lt;/strong&gt;&lt;/a&gt;, you must have used &lt;em&gt;npm&lt;/em&gt;. &lt;strong&gt;npm&lt;/strong&gt; is a dependency/package manager you get out of the box when you install  &lt;a href="https://nodejs.org"&gt;node&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;npm&lt;/em&gt; is two things really, first; &lt;em&gt;it is an online repository for the publishing of open-source Node.js projects&lt;/em&gt;; second, &lt;em&gt;it is a command-line utility for interacting with the said repository that aids in package installation, version management, and dependency management.&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since version  &lt;a href="https://github.com/npm/npm/releases/tag/v5.2.0"&gt;npm@5.2.0 - See Release Notes&lt;/a&gt;, &lt;strong&gt;&lt;em&gt;npx&lt;/em&gt;&lt;/strong&gt; is pre-bundled with &lt;strong&gt;npm&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Just like &lt;strong&gt;npm&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;npx&lt;/em&gt;&lt;/strong&gt; is a CLI tool but with special use cases. &lt;strong&gt;npx&lt;/strong&gt; is meant to make it easy to use CLI tools and other executables hosted on the &lt;strong&gt;npm&lt;/strong&gt; registry. &lt;/p&gt;

&lt;h2&gt;
  
  
  The npx Advantage? (Awesome Use Cases)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Most globally installed packages in node are executables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of globally installing node executable packages that you will likely use less often, you can save yourself disk space and simply run them with &lt;em&gt;npx&lt;/em&gt; when you need it. This means you can use any node executable package on &lt;strong&gt;npm&lt;/strong&gt; registry with having to install it.&lt;br&gt;
For example, I don't have to install &lt;em&gt;create-react-app&lt;/em&gt; globally on my machine and no worries about updates likewise because anytime I run &lt;code&gt;npx create-react-app&lt;/code&gt;, &lt;em&gt;npx&lt;/em&gt; will always look up the &lt;em&gt;npm&lt;/em&gt; registry and run the &lt;em&gt;create-react-app&lt;/em&gt; with its latest version.&lt;/p&gt;

&lt;p&gt;Installing npm packages globally most times requires &lt;strong&gt;&lt;em&gt;sudo&lt;/em&gt;&lt;/strong&gt; (administrative user right). With &lt;strong&gt;&lt;em&gt;npx&lt;/em&gt;&lt;/strong&gt; you can simply run a node executable anywhere without &lt;em&gt;sudo&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You don't have to install a CLI tool from npm registry when you only want to give it a try.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;npx &amp;lt;package/command&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can also use &lt;em&gt;npx&lt;/em&gt; to execute your scripts without adding $PATH variables. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;npx ./my-script.js&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Interestingly, you can combine &lt;em&gt;npx&lt;/em&gt; superpowers with  &lt;a href="https://www.npmjs.com/package/node"&gt;&lt;em&gt;node&lt;/em&gt;&lt;/a&gt;  package executable on npm registry which installs a node binary into your project (so you can have a local version of node that is different than your system's, and manage node like a normal dependency) just like &lt;strong&gt;&lt;em&gt;nvm&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
With this combination, you can run commands with different Node.js versions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;npx node@6 &amp;lt;package/command&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Do you have npm?
&lt;/h2&gt;

&lt;p&gt;Running this should return a path to the &lt;code&gt;npx&lt;/code&gt; bin.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ which npx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;If nothing is returned, it means you don't have a version of &lt;strong&gt;npm&lt;/strong&gt; greater than &lt;strong&gt;&lt;a href="mailto:npm@5.2.0"&gt;npm@5.2.0&lt;/a&gt;&lt;/strong&gt; running on your machine. The best bet is to upgrade your &lt;strong&gt;npm&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g npm@latest&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Useful Links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org"&gt;Install Node.js&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; &lt;a href="https://github.com/npm/npm/releases/tag/v5.2.0"&gt;See npm@5.2.0 Release Notes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/npm?activeTab=versions"&gt;Install npm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/nvm-sh/nvm"&gt;Install node via nvm&lt;/a&gt; &lt;em&gt;My Opinion: The best way to install node&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Start using npx today&lt;/em&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
