<?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: Rohit Ambre</title>
    <description>The latest articles on DEV Community by Rohit Ambre (@rohit_ambre).</description>
    <link>https://dev.to/rohit_ambre</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%2F463446%2F8d9a574a-72d9-4f4f-8362-65d7e4955cbf.jpeg</url>
      <title>DEV Community: Rohit Ambre</title>
      <link>https://dev.to/rohit_ambre</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohit_ambre"/>
    <language>en</language>
    <item>
      <title>Simple interactive CLI tool in Node/Javascript</title>
      <dc:creator>Rohit Ambre</dc:creator>
      <pubDate>Mon, 25 Mar 2024 15:06:19 +0000</pubDate>
      <link>https://dev.to/rohit_ambre/simple-interactive-cli-tool-in-nodejavascript-42ao</link>
      <guid>https://dev.to/rohit_ambre/simple-interactive-cli-tool-in-nodejavascript-42ao</guid>
      <description>&lt;p&gt;I was always fascinated with CLI tools provided by different applications, thinking that how simple and easy commands on CLI can result into such a big actions which can take quite a time to navigate through the UI.&lt;/p&gt;

&lt;p&gt;At my workplace I had one task that has to be done manually every time there's a need of doing it, which is a step-by-step process so I was thinking of automating it my level. I had two options, one is creating a small UI and other one is creating CLI tool. Me already wanting to create a CLI tool obviously chose a CLI tool 🤩.&lt;/p&gt;




&lt;p&gt;Here I will give you a small example about how can you create simple but very effective CLI tool in &lt;code&gt;nodeJS&lt;/code&gt; Using &lt;a href="https://www.npmjs.com/package/commander" rel="noopener noreferrer"&gt;Commander&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/inquirer" rel="noopener noreferrer"&gt;inquirer&lt;/a&gt; packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirement
&lt;/h2&gt;

&lt;p&gt;If you're going to use &lt;code&gt;inquirer&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NodeJS version &amp;gt;= &lt;code&gt;v18.12.0&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We're going to create a small Burger maker tool, which will accept inputs about bread, patty, toppings etc&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Commander&lt;/code&gt; is used to create CLI tool with commands and flags.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;inquirer&lt;/code&gt; provides ability to ask questions, interactivity and actions on the basis of answers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Start a new javascript project with &lt;code&gt;npm init -y&lt;/code&gt;&lt;br&gt;
&lt;code&gt;inquirer v9&lt;/code&gt; uses &lt;strong&gt;esm modules&lt;/strong&gt; hence you cannot use &lt;code&gt;commonjs&lt;/code&gt; syntax, to change your project to use module import/export change &lt;code&gt;type&lt;/code&gt; property in your &lt;code&gt;package.json&lt;/code&gt; file to &lt;code&gt;module&lt;/code&gt;. You can read more about esm modules &lt;a href="https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Import &lt;code&gt;commander&lt;/code&gt; and &lt;code&gt;inquirer&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Command&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;commander&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;inquirer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;inquirer&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;create a new Program using &lt;code&gt;Command&lt;/code&gt; class and add name along with some description.&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;const&lt;/span&gt; &lt;span class="nx"&gt;program&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;program&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;burger-maker&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="nf"&gt;description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Order a burger from CLI&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="nf"&gt;version&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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="nx"&gt;program&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now, try running your basic command on terminal.&lt;br&gt;
It should display command description with available options.&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%2F2te0e69tq2f894gb59ng.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%2F2te0e69tq2f894gb59ng.png" alt="burger-maker help"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, add &lt;code&gt;order&lt;/code&gt; command to the program and create basic questions using inquirer &lt;code&gt;prompts&lt;/code&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;const&lt;/span&gt; &lt;span class="nx"&gt;prompts&lt;/span&gt; &lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Your Name?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bun&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Choose a bun?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rawlist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;choices&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="s1"&gt;Classic&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;Whole Wheat&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;Gluten Free&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Classic&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;patty&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Choose a patty?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rawlist&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;choices&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="s1"&gt;Veg&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;Chicken&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;Today&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;s Special&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Veg&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toppings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Choose your favourite toppings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkbox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;choices&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="s1"&gt;Tomato&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;Lettuce&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;Cheese&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;Onion&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sauces&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Choose your favourite sauces&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkbox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;choices&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="s1"&gt;Mayonnaise&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;Ketchup&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;Mustard&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;These prompts are self explanatory, there are different types of prompts offered by &lt;strong&gt;inquirer&lt;/strong&gt; like &lt;code&gt;input, list, rawlist, checkbox, password&lt;/code&gt; etc. Prompts with documentations can be found here &lt;a href="https://github.com/SBoudrias/Inquirer.js?tab=readme-ov-file#prompts" rel="noopener noreferrer"&gt;github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;action&lt;/code&gt; listener on created &lt;code&gt;order&lt;/code&gt; command like below&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;order&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="nf"&gt;description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Order a burger&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="nf"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;answers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;inquirer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompts&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;answers&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;Now, when you run your &lt;code&gt;order&lt;/code&gt; command you'll get prompts to input the order details.&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%2F1xh52xgx479rw2vqldzn.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%2F1xh52xgx479rw2vqldzn.png" alt="order command output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point you can do whatever with the response, you can make &lt;code&gt;http&lt;/code&gt; api call and save in database.&lt;br&gt;
You can also make nested prompts to gather more information about particular item like below&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;const&lt;/span&gt; &lt;span class="nx"&gt;answers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;inquirer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompts&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;patty&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Chicken&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pattyAnswers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;inquirer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt; &lt;span class="c1"&gt;// new prompts here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;I also added small spinner by &lt;a href="https://www.npmjs.com/package/nanospinner" rel="noopener noreferrer"&gt;nanospinner&lt;/a&gt; and printed placed order details after a small delay.&lt;/p&gt;




&lt;h2&gt;
  
  
  Make it Globally available
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;main&lt;/code&gt; property in package.json to &lt;code&gt;index.js&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;#! /usr/bin/env node&lt;/code&gt; at the top of your file (this lines tells your OS to run this file with node interpreter)&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;bin&lt;/code&gt; property to package.json as follows.
```json
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"bin": {&lt;br&gt;
    "burger-maker": "./index.js"&lt;br&gt;
}&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Run `npm install -g .` to install this app 
- Now, open a new terminal and run `burger-maker -V`

![Final command output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iq8gtx3ush09jemxach.png)

NOTE: 

- if you're using Typescript give a path to a `dist/index.js` file
- If you're using `nvm` make sure correct node version to run the command

### ✅ There you go, You have your first CLI tool.
---
My example code is available on [Github Repo](https://github.com/rohit-ambre/burger-maker-cli/).



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

&lt;/div&gt;

</description>
      <category>cli</category>
      <category>node</category>
      <category>javascript</category>
      <category>learning</category>
    </item>
    <item>
      <title>Express starter with ORM, JWT, lint, logger, docker, etc</title>
      <dc:creator>Rohit Ambre</dc:creator>
      <pubDate>Tue, 13 Oct 2020 15:18:31 +0000</pubDate>
      <link>https://dev.to/rohit_ambre/express-starter-with-orm-jwt-lint-logger-docker-etc-2p55</link>
      <guid>https://dev.to/rohit_ambre/express-starter-with-orm-jwt-lint-logger-docker-etc-2p55</guid>
      <description>&lt;p&gt;When you are starting a new backend project in &lt;code&gt;Node.Js&lt;/code&gt; using &lt;code&gt;express&lt;/code&gt; there are things which are very common in every project and few files which are also required to be created in every project so, If you are going to start a new express project and want to quickly get started with basic app structure, database integration with ORM, JWT auth, linting, code styling, file-level logging, request validation, docker enabled then take a look here.&lt;/p&gt;

&lt;p&gt;Every express project will have &lt;code&gt;server.js&lt;/code&gt; or &lt;code&gt;index.js&lt;/code&gt; file to create an express app and start listening on any port. In Database, tables will at least have &lt;code&gt;users&lt;/code&gt; tables to store basic user details, and with users will surely have some sort of authentication mechanism, where mostly it's &lt;code&gt;JWT&lt;/code&gt; based authentication, so by keeping these things in mind, I made 2 boilerplates express apps one for Relation database (MySQL) using &lt;code&gt;sequelize&lt;/code&gt; ORM and second for Non-relational (MongoDB) database using &lt;code&gt;mongoose&lt;/code&gt; ORM. Both of these apps have &lt;code&gt;User&lt;/code&gt; model with basic user properties such as &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;firstName&lt;/code&gt;, &lt;code&gt;lastName&lt;/code&gt;, &lt;code&gt;password&lt;/code&gt;. Password is stored in hashed format and for authentication, it returns JWT token on successful login which is used to fetch all users API. So basically these boilerplates/starters have 3 APIs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;POST: &lt;code&gt;/api/auth/signup&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;POST: &lt;code&gt;/api/auth/login&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;GET: &lt;code&gt;/api/user/users&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To imply best practices, these apps use &lt;code&gt;eslint&lt;/code&gt; or &lt;code&gt;standard.js&lt;/code&gt;, for code styling it uses &lt;code&gt;prettier&lt;/code&gt;. (mysql one uses &lt;code&gt;standard.js&lt;/code&gt; for linting and styling while mongo one uses &lt;code&gt;eslint&lt;/code&gt; and &lt;code&gt;prettier&lt;/code&gt; for code styling.)&lt;br&gt;
Apps use &lt;a href="https://www.npmjs.com/package/express-validator" rel="noopener noreferrer"&gt;express-validator&lt;/a&gt; for request body validation in &lt;code&gt;POST&lt;/code&gt; APIs, uses &lt;a href="https://www.npmjs.com/package/winston" rel="noopener noreferrer"&gt;winston&lt;/a&gt; logger for logging error or debug data in file and console. I have tried to keep folder and code structure very simple to understand and to make changes according to your need.&lt;/p&gt;

&lt;p&gt;These are my two boilerplate repos&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Relational with Mysql
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rohit-ambre" rel="noopener noreferrer"&gt;
        rohit-ambre
      &lt;/a&gt; / &lt;a href="https://github.com/rohit-ambre/node-auth-mysql" rel="noopener noreferrer"&gt;
        node-auth-mysql
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Node(Express), Mysql based app with Authentication Boilerplate.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Non-relation with MongoDB
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rohit-ambre" rel="noopener noreferrer"&gt;
        rohit-ambre
      &lt;/a&gt; / &lt;a href="https://github.com/rohit-ambre/node-auth-mongo" rel="noopener noreferrer"&gt;
        node-auth-mongo
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Node(Express), MongoDB based app with Authentication Boilerplate.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;please show some ❤️ by starring ⭐ and making contributions in any form if you find anything.&lt;/p&gt;

&lt;p&gt;And for developers who wants to contribute during this &lt;code&gt;hacktoberfest&lt;/code&gt;, I would love to have contributions for the following stuff:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ideas for any new boilerplate repo.&lt;/li&gt;
&lt;li&gt;test setup (priority)&lt;/li&gt;
&lt;li&gt;unit test cases with optimum code coverage. (priority)&lt;/li&gt;
&lt;li&gt;better API documentation in markdown or etc&lt;/li&gt;
&lt;li&gt;bugs or issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm also working on two more, boilerplates repos which are not yet complete to get started which are &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Express in typescript using &lt;code&gt;TypeORM&lt;/code&gt; with &lt;code&gt;Postgres&lt;/code&gt; DB &lt;a href="https://github.com/rohit-ambre/express-ts" rel="noopener noreferrer"&gt;repo link&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Fastify app with &lt;code&gt;MongoDB&lt;/code&gt; &lt;a href="https://github.com/rohit-ambre/fastify-auth" rel="noopener noreferrer"&gt;repo link&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NOTE: &lt;em&gt;If you're going to contribute then before starting to work on it please create an issue explaining the bug or enhancement you want to work on, I'll assign it to you so, that no two users can work on the same thing&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thank you, tell me what you think about it.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Photo by &lt;a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Markus Spiske&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/starter?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>hacktoberfest</category>
    </item>
    <item>
      <title>add new non-null, unique column using Sequelize migration</title>
      <dc:creator>Rohit Ambre</dc:creator>
      <pubDate>Sun, 20 Sep 2020 17:43:24 +0000</pubDate>
      <link>https://dev.to/rohit_ambre/add-new-non-null-unique-column-using-sequelize-migration-1bh3</link>
      <guid>https://dev.to/rohit_ambre/add-new-non-null-unique-column-using-sequelize-migration-1bh3</guid>
      <description>&lt;p&gt;This short article is to explain how you can add a new &lt;code&gt;non-null&lt;/code&gt; and &lt;code&gt;unique&lt;/code&gt; column in an existing Relational database using &lt;code&gt;sequelize&lt;/code&gt; migration in nodeJS.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: This is for development environments and not recommended for production.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes while writing any application we might require to add new non-null and unique column in the existing database without dropping the current table, so I tried doing it in my demo project where I'm using sequelize ORM, and I'm writing this article because I couldn't find the complete solution at one place, so here's my attempt at solving this.&lt;/p&gt;

&lt;h4&gt;
  
  
  Problem description
&lt;/h4&gt;

&lt;p&gt;Consider we have &lt;code&gt;users&lt;/code&gt; table with the following columns and now we want to add a new &lt;code&gt;username&lt;/code&gt; column which has to be unique and non-null to this without dropping the table.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

| id | name  | email                 | age | hobby   |
|----|-------|-----------------------|-----|---------|
| 1  | bob   | bob@mars.com          | 23  | coding  |
| 2  | alice | alice01@jupyter.com   | 25  | dance   |
| 3  | John  | superjohn@earth.com   | 22  | singing |
| 4  | frank | frank@saturn.com      | 28  | reading |


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Solution
&lt;/h4&gt;

&lt;p&gt;One simple solution is to insert the same &lt;code&gt;email&lt;/code&gt; field in &lt;code&gt;username&lt;/code&gt; column as both are unique but we'll take general example where this is not possible.&lt;/p&gt;

&lt;p&gt;Let's start by creating a migration file using &lt;code&gt;sequelize-cli&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npx sequelize migration:create --name=add_username_users


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

&lt;/div&gt;

&lt;p&gt;Here's a screen capture of pseudo code&lt;br&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%2Fi%2F2pbdjycrv8objl559vmy.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%2Fi%2F2pbdjycrv8objl559vmy.png" alt="migration pseudo code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To explain, First we add &lt;code&gt;username&lt;/code&gt; column with just &lt;code&gt;unique&lt;/code&gt; constraint on its success we write any logic to update every row of newly added &lt;code&gt;username&lt;/code&gt; column with any logic you like. I used &lt;code&gt;{ type: QueryTypes.SELECT }&lt;/code&gt; in &lt;code&gt;SELECT&lt;/code&gt; query as we don't need metadata here and to get query results in an array on its success will alter the column to add &lt;code&gt;not-null&lt;/code&gt; constraint. For the down part of sequelize migration will just drop the &lt;code&gt;username&lt;/code&gt; column.&lt;/p&gt;

&lt;p&gt;Here's my final code to add a new column with a randomly generated username, which can be updated later or can be kept as it is during the development environment.&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;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;QueryTypes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sequelize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;up&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Sequelize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&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;username&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Sequelize&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sequelize&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`SELECT id from users`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;QueryTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;SELECT&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sequelize&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="s2"&gt;`UPDATE users SET username='&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;substr&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="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;' WHERE id=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;changeColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&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;username&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;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Sequelize&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;allowNull&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="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;down&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Sequelize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;queryInterface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&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;username&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;Thank you for reading and please share your thoughts on it.&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
random generation: &lt;a href="https://stackoverflow.com/a/8084248" rel="noopener noreferrer"&gt;stackOverflow answer&lt;/a&gt;&lt;br&gt;
code idea: &lt;a href="https://github.com/sequelize/sequelize/issues/5507#issuecomment-190736150" rel="noopener noreferrer"&gt;sequelize github issue&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>sequelize</category>
      <category>migration</category>
    </item>
    <item>
      <title>Does answering on Stackoverflow helps</title>
      <dc:creator>Rohit Ambre</dc:creator>
      <pubDate>Sun, 06 Sep 2020 14:24:31 +0000</pubDate>
      <link>https://dev.to/rohit_ambre/does-answering-on-stackoverflow-helps-3ogm</link>
      <guid>https://dev.to/rohit_ambre/does-answering-on-stackoverflow-helps-3ogm</guid>
      <description>&lt;p&gt;As a developer we always tend to open &lt;strong&gt;stackoverflow&lt;/strong&gt;(SO) more than any other site while writing code. And I must say stackoverflow never disappoint us. In some cases even though we don't find the exact solution to our questions we get enough idea to work on the solutions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8km7yzyor9ms4f2p2ynw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8km7yzyor9ms4f2p2ynw.png" alt="searching through stack" width="687" height="31"&gt;&lt;/a&gt;&lt;br&gt;
So during this lockdown period because of Covid-19, I thought why not to start helping others instead of just using SO, let's start answering or helping in any way possible. Initially when I started it was lot difficult to understand questions that are being asked and even now they are difficult 😅. I have seen people posting answers of 200 lines with tons of description and that's great but that really takes lot of experience and expertise in that domain, so I started with watching &lt;code&gt;#javascript&lt;/code&gt; tag and on SO till you don't have 50 reputations you can't comment, so reaching 50 reputation mark was the first target and it took efforts for me to get there by editing questions or answering...&lt;/p&gt;

&lt;p&gt;I knew about Bronze, Silver and Gold 🏅 badges that users have but the way this badges are earned is what I found very interesting like every badge is a challenge so to earn that particular badge you'll have to complete whatever the listed requirement is and that way I found it very addictive and challenging to work on those challenges to earn new badges. &lt;/p&gt;

&lt;h3&gt;
  
  
  StackOverflow helps at
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improves debugging skills:&lt;/strong&gt; Just by reading question and  given example code you need understand what is the issue and most of times you can't reproduce the error at your end so just on the basis of reading you need to find out the errors. It really improves your debugging skills when you'll work on your project as well.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Answers with code:&lt;/strong&gt; Sometimes users explain their idea and then you get the chance to help them improve their ideas by your experience or you can post example code for them to understand your thought process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Import-export of ideas:&lt;/strong&gt; When your giving an answer to any question there answers from other users too by which you can understand what are the other ways you can achieve same result vice versa for other users. So now you know more ways to do same thing. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pleasure of helping😀:&lt;/strong&gt; The feeling you get once your answer gets accepted by the user who questioned and 'Thank You' comment is really something very inspiring and motivating for me to try and help others wherever I can.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boosts confidence:&lt;/strong&gt; StackOverflow is THE site in the world known to each and every developer and earning reputations on it boosts your confidence. You can also include reputation count on your resume👌.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the first article I have ever written, I don't know how well and how helpful it would be for dev community but I always wanted to do it. The day I'm posting this article is my 99th Consecutive day on Stackoverflow that means tomorrow I'll get my First Gold (Fanatic) badge and I'm so excited. Every day I spent some time on SO to help community by any means possible.&lt;/p&gt;

&lt;p&gt;I would really suggest you to join stackoverflow and try your knowledge and grow your knowledge by helping others, You'll love it.&lt;/p&gt;

&lt;p&gt;Comment and let me know about your thoughts.&lt;br&gt;
Stay safe.&lt;br&gt;
Thank you. &lt;/p&gt;

</description>
      <category>community</category>
      <category>stackoverflow</category>
    </item>
  </channel>
</rss>
