<?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: Bagus Budi Cahyono</title>
    <description>The latest articles on DEV Community by Bagus Budi Cahyono (@bagusbudicahyono).</description>
    <link>https://dev.to/bagusbudicahyono</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%2F285687%2F94681a2a-7cf1-4802-9bfc-2952e9670211.jpeg</url>
      <title>DEV Community: Bagus Budi Cahyono</title>
      <link>https://dev.to/bagusbudicahyono</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bagusbudicahyono"/>
    <language>en</language>
    <item>
      <title>An Approach to Organize Optional Function Parameter in Javascript</title>
      <dc:creator>Bagus Budi Cahyono</dc:creator>
      <pubDate>Tue, 20 Jul 2021 06:57:14 +0000</pubDate>
      <link>https://dev.to/bagusbudicahyono/a-better-approach-to-organize-optional-function-parameter-in-javascript-4kl7</link>
      <guid>https://dev.to/bagusbudicahyono/a-better-approach-to-organize-optional-function-parameter-in-javascript-4kl7</guid>
      <description>&lt;p&gt;Optional parameters in a function are very common. You can define and organize your function and parameters as you want. But, are you sure that your function and parameters are easy to understand and easy to use? If you are not sure, you should read this post.&lt;/p&gt;

&lt;p&gt;In this post, I will give you suggestions and approach on how to define your optional parameter in javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional Parameter
&lt;/h2&gt;

&lt;p&gt;In Javascript, the default value of the function parameter is &lt;code&gt;undefined&lt;/code&gt;. So, if you define a parameter but you don't provide it in the function call, the value will be &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// hello undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's make the parameter to be an optional parameter (or default parameter) by adding a default value for the parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;guest&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// hello guest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, when we add a default value to a parameter, it becomes an optional parameter, which means you don't have to provide a value in the function call. Easy right? Hold on, let's take a look at a function that has many parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem of Optional Parameter
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;makeSmoothie&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sugarLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;topping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pudding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;small&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;// code to make a smoothie&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have a sample function &lt;code&gt;makeSmothie&lt;/code&gt;, which has 1 required parameter, and 3 optional parameters (&lt;code&gt;sugarLevel&lt;/code&gt;, &lt;code&gt;topping&lt;/code&gt;, &lt;code&gt;size&lt;/code&gt;). In case you wrote code like this, you better keep reading this post.&lt;/p&gt;

&lt;p&gt;Next, If I want to make a mango smoothie, I can call the function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&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;If I want to make a mango smoothie that is sweeter than the first one, I change sugarLevel to 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, there is no problem at all. However, what if I want to make a smoothie, but don't like pudding as the topping, So I decide to make a smoothie with red bean topping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red bean&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;As you can see, what I actually want is to only change the topping, but, in fact, I have to provide sugarLevel value when calling the function.&lt;/p&gt;

&lt;p&gt;Even worst, when I only want to change the size of the smoothie, I have to give the value of all optional parameters before the &lt;code&gt;size&lt;/code&gt; parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&lt;/span&gt;&lt;span class="dl"&gt;'&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pudding&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="s1"&gt;medium&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;Are these really optional parameters? Why do I still have to give a value for &lt;code&gt;sugarLevel&lt;/code&gt; and &lt;code&gt;topping&lt;/code&gt;?  This is just a sample case to show you the problem you might face if you write code similar to the sample. Let's solve the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Approach to Define Optional Parameters
&lt;/h2&gt;

&lt;p&gt;In order to solve the problem, we can follow these rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the function only has 1 optional parameter, put it in the very last after all required parameters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;makeSmoothie&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sugarLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;// code to make a smoothie&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If the function has more than 1 optional parameter, use &lt;code&gt;Object&lt;/code&gt; and &lt;code&gt;Object Destructuring&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;makeSmoothie&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sugarLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;topping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pudding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;small&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}){&lt;/span&gt;
    &lt;span class="c1"&gt;// code to make a smoothie&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have two parameters, let's call them &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;variant&lt;/code&gt;. We can call the function in a more efficient way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&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="na"&gt;sugarLevel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&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="na"&gt;topping&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red bean&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nx"&gt;makeSmoothie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mango&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="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;medium&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;That's the approach I prefer to use. If you have another solution, share yours in the comment section.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Easy Way to Install Multiple Version of Node JS</title>
      <dc:creator>Bagus Budi Cahyono</dc:creator>
      <pubDate>Sun, 04 Jul 2021 02:22:35 +0000</pubDate>
      <link>https://dev.to/bagusbudicahyono/easy-way-to-install-multiple-version-of-node-js-78e</link>
      <guid>https://dev.to/bagusbudicahyono/easy-way-to-install-multiple-version-of-node-js-78e</guid>
      <description>&lt;p&gt;Basically, installing Node JS on your machine is very easy. &lt;/p&gt;

&lt;p&gt;If you are using mac or windows, you can just download the package from the official website, then install it. Alternatively, you can install it via Homebrew for mac.&lt;/p&gt;

&lt;p&gt;If you are using Linux, just install it via the package manager of your Linux distro, for example, use pacman for Arch Linux, and use apt-get for Debian-based. When your installation process is successful, you will have one version of Node js.&lt;/p&gt;

&lt;p&gt;In some cases, you need multiple versions of Node JS on your computer. Especially if you work with multiple projects that require a different version of Node JS. Another reason that might make you want to install multiple versions is that you might want to use the LTS version for your current project but you also want to try new features of the latest version of Node JS. The best solution is to install two or more versions of Node JS on your computer. In case you are under the same circumstances, this post is right for you.&lt;/p&gt;

&lt;p&gt;In this post, I will show you how to install multiple Node JS on your computer with the help of NVS (Node Version Switcher). NVS is a cross-platform utility for switching between different versions of Node JS. You can easily install and switch to a different version of Node JS anytime you want.&lt;/p&gt;

&lt;p&gt;NVS Installation process only takes less than a minute. Below are the steps to install it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install NVS on Windows
&lt;/h2&gt;

&lt;p&gt;There are two ways to install nvs on your windows computer. You don't need to do both,  you can choose one of them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download the &lt;a href="https://github.com/jasongin/nvs/releases/tag/v1.6.0" rel="noopener noreferrer"&gt;NVS msi file here&lt;/a&gt; (windows installer), then install it the same way as you install other windows applications.&lt;/li&gt;
&lt;li&gt;Use chocolatey (choco). Make sure you already have choco installed. Go to &lt;a href="https://chocolatey.org/" rel="noopener noreferrer"&gt;the chocolatey official website&lt;/a&gt; if you do not install it yet. When you have choco, you can install NVS by running this command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;choco &lt;span class="nb"&gt;install &lt;/span&gt;nvs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install NVS on Mac and Linux
&lt;/h2&gt;

&lt;p&gt;You only need to run this command to install NVS on your mac / Linux.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NVS_HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.nvs"&lt;/span&gt;
git clone &amp;lt;https://github.com/jasongin/nvs&amp;gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVS_HOME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVS_HOME&lt;/span&gt;&lt;span class="s2"&gt;/nvs.sh"&lt;/span&gt; &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will add variable NVS_HOME which has value path &lt;code&gt;$HOME/.nvs&lt;/code&gt;. For example, If my home directory is &lt;code&gt;/Users/baggus/&lt;/code&gt;, then NVS_HOME is &lt;code&gt;/Users/baggus/.nvs&lt;/code&gt;  This location will be used by nvs to put nvs code and your Node JS installation.&lt;/p&gt;

&lt;p&gt;The second line of the command is to clone the nvs repository and put it inside NVS_HOME directory. The last command, it will run nvs.sh, which will add nvs shell function to the environment. The install command will add lines on your &lt;code&gt;~/.bashrc&lt;/code&gt;, &lt;code&gt;~/.profile&lt;/code&gt;, or &lt;code&gt;~/.zshrc&lt;/code&gt; file to source nvs.sh (depending on what shell you use). With this command, the nvs command will be available in your shells.&lt;/p&gt;

&lt;p&gt;After you have successfully installed nvs, you can verify the installation by run command on your shell/terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Managing multiple versions of Node JS via NVS
&lt;/h2&gt;

&lt;p&gt;Now you have NVS installed on your computer. Let's start installing Node JS. In this example, I will show you how to install two versions of Node JS, and how to switch versions between them.&lt;/p&gt;

&lt;p&gt;Actually, you have two options, you can use an interactive menu of nvs, or you can type your command as you want. For accessing the interactive menu, you run the command &lt;code&gt;nvs&lt;/code&gt; without any parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the command executed, you will see the interactive menu like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fal3hskmrbwfk71xiim2m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fal3hskmrbwfk71xiim2m.png" alt="Interactive Menus NVS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you can choose a specific version of Node JS that you want to use. After you choose a version, nvs will download and install Node JS for you. Next time you run nvs command, you will see like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2zk2kq35dgo3ki92ombg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2zk2kq35dgo3ki92ombg.png" alt="Interactive menus when Node JS is installed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I choose to install Node vesion 14.17.2. It will show up on interactive menu. I think this is really easy so that you can do it on your own.&lt;/p&gt;

&lt;p&gt;Next, I will show you how to do it via nvs command. In this example, I want to install the LTS version and the latest version. When I write this post, the LTS version is 14.17.2 and the latest version is 16.4.1&lt;/p&gt;

&lt;p&gt;Follow these steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install v14.17.2 (LTS)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs add 14.17.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can also simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs add lts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Check the list of Node version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see that version 14 there. It means that your installation of version 14 is successful. Your Node JS 14 is installed on &lt;code&gt;~/.nvs/node/14.17.2/&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start to use version 14
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs use 14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs use lts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command nvs use is to switch versions for your current shell only. When you close your shell, the version used is still the default version. If you want to use it permanently (as your default), run nvs link lts&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the Node JS version you use
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt;

// will show output
// v14.17.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I will install version 16 (latest), and switch to that version.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install version 16
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs add 16.4.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs add latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Switch to that version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs use 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvs use latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Check Node version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;-v&lt;/span&gt;

// will show output
// v16.4.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have already familiar with the nvs command. It is really easy to use. I highly recommend you to use nvs or other node version managers before starting to develop a Node JS application.&lt;/p&gt;

&lt;p&gt;To see the list of all nvs commands, check &lt;a href="https://github.com/jasongin/nvs#command-reference" rel="noopener noreferrer"&gt;command reference&lt;/a&gt; on nvs repository.&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jasongin/nvs" rel="noopener noreferrer"&gt;https://github.com/jasongin/nvs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;https://nodejs.org/en/&lt;/a&gt;&lt;/p&gt;

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