<?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: Karan Sharma</title>
    <description>The latest articles on DEV Community by Karan Sharma (@curiouskaran).</description>
    <link>https://dev.to/curiouskaran</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%2F407927%2F1c6f9cb8-0a17-4d82-ab31-35202282a5c7.jpeg</url>
      <title>DEV Community: Karan Sharma</title>
      <link>https://dev.to/curiouskaran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/curiouskaran"/>
    <language>en</language>
    <item>
      <title>Automate your workflow using NodeJS CLI programs</title>
      <dc:creator>Karan Sharma</dc:creator>
      <pubDate>Sat, 13 Jun 2020 07:12:08 +0000</pubDate>
      <link>https://dev.to/curiouskaran/automate-your-workflow-using-nodejs-cli-programs-45e1</link>
      <guid>https://dev.to/curiouskaran/automate-your-workflow-using-nodejs-cli-programs-45e1</guid>
      <description>&lt;p&gt;Automating your workflow shifts the focus from doing the unnecessary and repetitive task to a more important thing and prevents us from procrastinating. As a JS developer, I always want something that prevents fiddling for things around BASH while writing my workflows and gives me confidence and control over the task in hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps for Writing a simple CLI program
&lt;/h2&gt;

&lt;p&gt;In this, I will take one trivial task of opening the projects or run specific commands like running tests over them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Always begin your scripts with&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YftVJh65--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2abswo845okvw06oov1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YftVJh65--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2abswo845okvw06oov1i.png" alt="Start of Script"&gt;&lt;/a&gt;&lt;br&gt;
This is to specify that it is a node script and to be treated as CLI program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Helpers for making it more easy and fun&lt;/strong&gt;&lt;br&gt;
This list includes &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P0b23mnt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1njgjcjkcr6gdolova6q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P0b23mnt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1njgjcjkcr6gdolova6q.png" alt="helper programs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Breakdown your requirements in form of JSON object&lt;/strong&gt; &lt;br&gt;
Writing your requirements in JSON makes it easy to extend and review changes later on.&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fm_dNLlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s879geb72264teuwzzjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fm_dNLlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s879geb72264teuwzzjn.png" alt="Config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) Writing the workflow&lt;/strong&gt;&lt;br&gt;
Don't over complicate things and just write simple reusable functions that can be used across all your CLI tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--993Fxkca--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jydua92mk7y90tbah474.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--993Fxkca--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jydua92mk7y90tbah474.png" alt="main flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5) Making it installable and accessible from anywhere.&lt;/strong&gt;&lt;br&gt;
Make an entry in package.json of your project specifying the initial point of the script.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vKXknZ7i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0f7sl2ejjtzzyrjpnlj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vKXknZ7i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0f7sl2ejjtzzyrjpnlj6.png" alt="trick"&gt;&lt;/a&gt;&lt;br&gt;
and then running &lt;code&gt;npm link&lt;/code&gt; in the directory will install it like any other CLI program in &lt;code&gt;/usr/bin&lt;/code&gt;.&lt;br&gt;
This little trick makes it accessible when used from anywhere like in the above example &lt;code&gt;workflow&lt;/code&gt; can be invoked from CLI globally.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jNXtnq4x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nvya7rpakx86ad1bh1px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jNXtnq4x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nvya7rpakx86ad1bh1px.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the complete code for this tool at my github repo.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/curiouskaran"&gt;
        curiouskaran
      &lt;/a&gt; / &lt;a href="https://github.com/curiouskaran/projectOpener"&gt;
        projectOpener
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Open a project that has alias listed in a json
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;
 

&lt;p&gt;Thanks for reading! Please let me know in the comments for any thoughts and improvements.&lt;/p&gt;

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