<?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>Forem: Chetan</title>
    <description>The latest articles on Forem by Chetan (@chetan_raj).</description>
    <link>https://forem.com/chetan_raj</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%2F37449%2Fbcd43542-3bab-46a8-a1a4-acdabe76bff6.jpg</url>
      <title>Forem: Chetan</title>
      <link>https://forem.com/chetan_raj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chetan_raj"/>
    <language>en</language>
    <item>
      <title>Things I Don't Know as of 2020</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Wed, 30 Dec 2020 18:26:16 +0000</pubDate>
      <link>https://forem.com/chetan_raj/things-i-don-t-know-as-of-2020-1co6</link>
      <guid>https://forem.com/chetan_raj/things-i-don-t-know-as-of-2020-1co6</guid>
      <description>&lt;p&gt;People assume that being in any industry for more than a few years one should know just about everything. That's so not true! In this post, I am listing out the things which I'm not aware-of or currently learning.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Not knowing everything is ok&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;List of things I don't know&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unix commands and bash -  I can manage with &lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;cd&lt;/code&gt; and the world-famous &lt;code&gt;rm -rf&lt;/code&gt; Can manage with grep but for everything else I’ve to lookup.&lt;/li&gt;
&lt;li&gt;CSS Methodologies - No BEMs, No OOCSS I can do Tailwind CSS or styled-components easily. CSS-in-JS is the one I'm rocking now🤘&lt;/li&gt;
&lt;li&gt;TypeScript - Type checking in JavaScript is not my cup of coffee  ☕&lt;/li&gt;
&lt;li&gt;Generators - Stream data only using JavaScript 😱&lt;/li&gt;
&lt;li&gt;Containers - I can create a docker and launch a container, nothing more than that 📦&lt;/li&gt;
&lt;li&gt;Animations - Using CSS or SVG Animations, gets on my nerves.&lt;/li&gt;
&lt;li&gt;Python - No "Hello World!!" also. 🐍&lt;/li&gt;
&lt;li&gt;Machine Learning - Maybe will take up next year 🎰&lt;/li&gt;
&lt;li&gt;Testing - I can handle Unit testing in JavaScript, React and Vue, but automating everything in one click is what I've to get hold of in 2021 🔥&lt;/li&gt;
&lt;li&gt;Redux - Haven't got the change to look at it&lt;/li&gt;
&lt;li&gt;AWS - This is where my current focus is, I've started a bit or two. AWS Amplify is making my life easy 😇&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I'm aware of the knowledge gaps that are created over time. Learning never ends, it's always good to keep learning&lt;/p&gt;

&lt;p&gt;💡 Post inspired by &lt;a href="https://overreacted.io/things-i-dont-know-as-of-2018/"&gt;Dan Abramov's&lt;/a&gt;&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--F1YgPzW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1336281436685541376/fRSl8uJP_normal.jpg" alt="Dan Abramov profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Dan Abramov
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/dan_abramov"&gt;@dan_abramov&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      📝 New on Overreacted: Things I Don’t Know as of 2018. We can admit our knowledge gaps without devaluing our expertise. &lt;a href="https://t.co/0VJ76yPvzg"&gt;overreacted.io/things-i-dont-…&lt;/a&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      13:53 PM - 28 Dec 2018
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1078650200221204480" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1078650200221204480" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      1970
      &lt;a href="https://twitter.com/intent/like?tweet_id=1078650200221204480" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      6464
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


</description>
    </item>
    <item>
      <title>⛓ The optional chaining operator in JavaScript</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Sat, 02 May 2020 14:46:14 +0000</pubDate>
      <link>https://forem.com/chetan_raj/the-optional-chaining-operator-in-javascript-3bbk</link>
      <guid>https://forem.com/chetan_raj/the-optional-chaining-operator-in-javascript-3bbk</guid>
      <description>&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;p&gt;The optional chaining operator &lt;code&gt;?.&lt;/code&gt; permits reading the value of a property located deep within a chain of connected objects.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The optional chaining was introduced as part of the ES2020 standard.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why this ?
&lt;/h2&gt;

&lt;p&gt;It changes the way we access the properties from the deep objects. The optional chaining makes your code look cleaner 🧼 and crisp 🔥&lt;/p&gt;

&lt;p&gt;Consider this piece of code, where the data object has a query and an answer to the query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"What is javascript ?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"answer"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"JavaScript is 💛"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To access the &lt;code&gt;value&lt;/code&gt;, you have to write a loooong conditional statement which is difficult to read and format 😢&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;theValue&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;response&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="nx"&gt;response&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="nx"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="nx"&gt;response&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="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;theValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&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="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;theValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JavaScript is BAE 💛❤️&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But with optional chaining, you can access the &lt;code&gt;value&lt;/code&gt; easily 😃 and you don't have to worry about the null &amp;amp; undefined checks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;response&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="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;

&lt;span class="c1"&gt;// Output&lt;/span&gt;
&lt;span class="nx"&gt;JavaScript&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="err"&gt;💛&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Wow, this code looks so clean 🧼 and crisp !! If the &lt;code&gt;value&lt;/code&gt; is not present, we can assign a default value to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;response&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="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JavaScript is BAE 💛❤️&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// Output&lt;/span&gt;
&lt;span class="nx"&gt;JavaScript&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;BAE&lt;/span&gt; &lt;span class="err"&gt;💛❤️&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up the Babel Plugin
&lt;/h2&gt;

&lt;p&gt;Babel &lt;a href="https://babeljs.io/blog/2020/01/11/7.8.0"&gt;7.8.0&lt;/a&gt; supports the new &lt;code&gt;ECMAScript 2020&lt;/code&gt; features by default. There is no need of enabling an individual plugin for optional chaining (&lt;code&gt;?.&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;If you are using the latest Babel version which is above or equal to 7.8.0, then it's an easy setup&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @babel/cli @babel/core @babel/preset-env
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now add the following configuration to the &lt;code&gt;.babelrc&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"presets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"@babel/preset-env"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The necessary babel modules and the preset configurations are done. Now it's time to do the babel magic ✨&lt;/p&gt;

&lt;p&gt;Run this command to transpile the code to the supported version everywhere. This command will work if you have installed the &lt;code&gt;babel&lt;/code&gt; module globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;babel app.js &lt;span class="nt"&gt;--out-file&lt;/span&gt; script-transpiled.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All the optional chaining code should be placed in &lt;code&gt;app.js&lt;/code&gt; and then the above command should be executed. This produces the transpiled code which works in major browsers and in &lt;code&gt;node.js&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different types of optional chaining
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Optional chaining with function calls
&lt;/h3&gt;

&lt;p&gt;Optional chaining can be used when you are trying to invoke a method which may not exist. Using optional chaining with function calls causes the expression to automatically return undefined instead of throwing an exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Operation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;getSum&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Operation&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;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 5&lt;/span&gt;

&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDiff&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output - Uncaught TypeError: o.getDiff is not a function&lt;/span&gt;

&lt;span class="c1"&gt;// Check if the function exists&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDiff&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDiff&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

&lt;span class="c1"&gt;// With the use of optional chaining&lt;/span&gt;
&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getDiff&lt;/span&gt;&lt;span class="p"&gt;?.()&lt;/span&gt; &lt;span class="c1"&gt;// Output - undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Optional chaining with expression
&lt;/h3&gt;

&lt;p&gt;If the left operand is null or undefined, the expression after the optional chaining operator will not be evaluated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isTeenage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;isTeenage :: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isTeenage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//Output&lt;/span&gt;

&lt;span class="nl"&gt;isTeenage&lt;/span&gt; &lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The user is defined as null, while executing the line #3, the &lt;code&gt;isTeenage&lt;/code&gt; didn't throw any error because if the left operand is null or undefined, the expression will not be evaluated.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Combining with the nullish coalescing operator [which is another &lt;em&gt;ES2020&lt;/em&gt; feature]
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isTeenage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="nx"&gt;value&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not a teenager !!&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;isTeenage :: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isTeenage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Output&lt;/span&gt;

&lt;span class="nl"&gt;isTeenage&lt;/span&gt; &lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;teenager&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Things about optional chaining
&lt;/h2&gt;

&lt;p&gt;🚀 Clean &amp;amp; Readable code&lt;br&gt;
🚀 Don't worry about &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; in an object&lt;br&gt;
🚀 Less error&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Chrome - 80&lt;/li&gt;
&lt;li&gt;Edge - 80&lt;/li&gt;
&lt;li&gt;Firefox - 74&lt;/li&gt;
&lt;li&gt;Internet Explorer - NO&lt;/li&gt;
&lt;li&gt;Opera - 67&lt;/li&gt;
&lt;li&gt;Node.js - 14.0.0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining"&gt;MDN web docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>What is context path ?</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Sat, 28 Mar 2020 17:39:38 +0000</pubDate>
      <link>https://forem.com/chetan_raj/what-is-context-path-4cdg</link>
      <guid>https://forem.com/chetan_raj/what-is-context-path-4cdg</guid>
      <description>&lt;p&gt;The context path is the prefix of a URL path that is used to select the context(s) to which an incoming request is passed. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Context path is also known as sub-path or sub-directory&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Many apps are hosted at something other than the root (/) of their domain. For example, My personal blog is live at &lt;a href="https://chetanraj.in/blog"&gt;https://chetanraj.in/blog,&lt;/a&gt; or you can host your site on GitHub Pages at &lt;a href="http://example.github.io/blog/"&gt;https://example.github.io/blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Each of these sites need a prefix added to all paths on the site. So a link to a blog which is having the slug /features-in-es6/ should be rewritten as /blog/features-in-es6.&lt;/p&gt;

&lt;p&gt;In addition to the slug of the blog, links to various resources (JavaScript, CSS, images, and other static content) need the same prefix, so that the site continues to function correctly when served with the path prefix in place.&lt;/p&gt;

&lt;p&gt;For this to work, you need to specify the config according to them. This allows the built bundle to be deployed under that path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some examples where you need to specify the context path before building your app.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create React App
&lt;/h2&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json

{
  ...
  "homepage": ".",
  ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Vue
&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// vue.config.js

module.exports = {
  baseUrl: '/blog',
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Gatsby
&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// gatsby-config.js

module.exports = {
  pathPrefix: '/blog',
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Also, If you are serving static files, then paste the sub-directory folder in the root folder. This will serve from the sub-directory.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>contextpath</category>
      <category>react</category>
      <category>vue</category>
    </item>
    <item>
      <title>My Top Ten VS Code Plugins</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Fri, 24 Jan 2020 09:30:39 +0000</pubDate>
      <link>https://forem.com/chetan_raj/my-top-ten-vs-code-plugins-4m8e</link>
      <guid>https://forem.com/chetan_raj/my-top-ten-vs-code-plugins-4m8e</guid>
      <description>&lt;h2&gt;
  
  
  #1 — Peacock
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--82CeSHsl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWwbBEwh-NXEZOFh-XxUmBQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--82CeSHsl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWwbBEwh-NXEZOFh-XxUmBQ.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #2 — Bracket Pair Colorizer 2
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mz7EhSyU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A8WJv4vmvY-sK0Dg4W1wceg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mz7EhSyU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A8WJv4vmvY-sK0Dg4W1wceg.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #3 — Material Theme
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QtNcil-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AI2VDi1XmBzTRhu_rex0_rA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QtNcil-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AI2VDi1XmBzTRhu_rex0_rA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #4 — GitLens
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrocfw13--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A0eETh-Arjp2hPDB17_9kWw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrocfw13--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A0eETh-Arjp2hPDB17_9kWw.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #5 — Auto Close Tag
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hOIy3SqL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A9yTHnI4RpIPHvKqvD7yciQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hOIy3SqL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2A9yTHnI4RpIPHvKqvD7yciQ.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #6 — Better Comments
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n3SHfMQF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWMzfi-fDnQ-1a7zE4BhHBA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n3SHfMQF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWMzfi-fDnQ-1a7zE4BhHBA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #7 —Import Cost
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fHKwTalL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2Aobq-fMXcgIGOWPpZdTUdDQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fHKwTalL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2Aobq-fMXcgIGOWPpZdTUdDQ.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #8— Debugger for Chrome
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A7Q1Fx2Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWxe5gtfoKGlElsDXTD-p4A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A7Q1Fx2Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWxe5gtfoKGlElsDXTD-p4A.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #9 — Turbo Console Log
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--91Zhhcev--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWFZuq9_q9kLcOfIeVVZJsg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--91Zhhcev--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/8534/1%2AWFZuq9_q9kLcOfIeVVZJsg.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  #10 — Prettier
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5D7etw1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2048/1%2Aur7nfBmepIoGo0xAzvFYrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5D7etw1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2048/1%2Aur7nfBmepIoGo0xAzvFYrw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>web</category>
    </item>
    <item>
      <title>compose in styled-system</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Wed, 31 Jul 2019 18:41:42 +0000</pubDate>
      <link>https://forem.com/chetan_raj/compose-in-styled-system-3b4d</link>
      <guid>https://forem.com/chetan_raj/compose-in-styled-system-3b4d</guid>
      <description>&lt;p&gt;As per the &lt;a href="https://styled-system.com/api/#compose"&gt;document&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The compose utility is used to combine multiple style functions together into one. This utility can help improve performance when using multiple style props functions on the same component.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this post let us build a Button component using the styled-components and styled-system as shown below. Let us build this component using &lt;strong&gt;border, color, shadow, space &amp;amp; typography&lt;/strong&gt; functions from the styled-system.&lt;/p&gt;

&lt;p&gt;import styled from 'styled-components';&lt;br&gt;
    import { border, color, shadow, space, typography } from 'styled-system';&lt;/p&gt;

&lt;p&gt;const Buttons = styled.div(&lt;br&gt;
        border,&lt;br&gt;
        color,&lt;br&gt;
        shadow,&lt;br&gt;
        space,&lt;br&gt;
        typography&lt;br&gt;
    );&lt;/p&gt;

&lt;p&gt;export default Buttons;&lt;/p&gt;

&lt;p&gt;So when we use multiple functions like border, color, shadow, space &amp;amp; typography, this will invoke multiple functions on render which will hamper the performance of app. It is even worse when the whole component is wrapped with state.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Here comes the compose function to the rescue which is the super hero 💠 of styled-system API. The compose function will combine the multiple functions into one, which will invoke only one function on render [saved by the compose function 😊]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;import styled from 'styled-components';&lt;br&gt;
    import { compose, border, color, shadow, space, typography } from 'styled-system';&lt;/p&gt;

&lt;p&gt;const Buttons = styled.div(&lt;br&gt;
      compose(&lt;br&gt;
        border,&lt;br&gt;
        color,&lt;br&gt;
        shadow,&lt;br&gt;
        space,&lt;br&gt;
        typography&lt;br&gt;
      )&lt;br&gt;
    );&lt;/p&gt;

&lt;p&gt;export default Buttons;&lt;/p&gt;

&lt;p&gt;So using the above component, you can define any kind of a &lt;code&gt;&amp;lt;Button /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Click here&lt;/p&gt;

&lt;p&gt;Disabled&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cssinjs</category>
      <category>styledsystem</category>
      <category>designsystem</category>
    </item>
    <item>
      <title>Build a RESTful API using hapijs and mongoose</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Wed, 24 Oct 2018 07:52:08 +0000</pubDate>
      <link>https://forem.com/chetan_raj/build-a-restful-api-using-hapijs-and-mongoose-33j4</link>
      <guid>https://forem.com/chetan_raj/build-a-restful-api-using-hapijs-and-mongoose-33j4</guid>
      <description>&lt;p&gt;The API will handle CRUD for an object[&lt;a href="https://en.wikipedia.org/wiki/Wolf_%28disambiguation%29"&gt;Wolf&lt;/a&gt;], Using the HTTP verbs — GET, PUT, POST and DELETE&lt;/p&gt;

&lt;p&gt;Okay, Let’s start&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make sure you’ve node installed in your machine and yarn as a global package&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a project directory name “/hapijs-mongoose-restapi” and run the command and fill the required details.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Specify the main file as app.js&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;yarn init is similar to npm init, this will generate the package.json file, Refer &lt;a href="https://yarnpkg.com/"&gt;yarn&lt;/a&gt; for more.&lt;/p&gt;

&lt;p&gt;then install the node_modules we need for this API&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add hapi mongoose --dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Building the hapi server, In the app.js&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Hapi = require('hapi');
const server = new Hapi.Server();

server.connection({
    host: 'localhost',    
    port: 4000
});

server.route({
    method: 'GET',
    path: '/',
    handler(request, reply) {
    reply('Hello, world!');
    }
});

server.route({
    method: 'GET',
    path: '/api',
    handler(request, reply) {
    reply('Hello, API!');
    }
});

server.start(err =&amp;gt; {
    if (err) {
    throw err;
    }
    console.log(`Server running at: ${server.info.uri}`);
});

exports.server = server;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;server.connection — To connect to the server with the host and port&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;server.route — Will contain the route object&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In the server.router, the handler will return using the return() API — &lt;a href="http://hapijs.com/api#replyerr-result"&gt;http://hapijs.com/api#replyerr-result&lt;/a&gt;, where the return is used to conclude the handler activity by setting a response and returning the response and status to the handler.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;server.start — To start the server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Starting the server and testing the index route&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nodemon app.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://medium.com/jsessentials/using-nodemon-for-auto-reload-of-server-after-code-change-74c9901a1d98"&gt;&lt;strong&gt;Using nodemon for auto-reload of server after code change for node.js applications&lt;/strong&gt;&lt;br&gt;
*Was a newbie to node.js, whenever I make a change in the code, In the terminal i used to keep on hitting Ctrl+C and…*medium.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s test the API using &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt; — Chrome App/Mac App.&lt;/p&gt;

&lt;p&gt;open Postman, select the &lt;strong&gt;GET&lt;/strong&gt; HTTP verb and enter the url &lt;a href="http://localhost:4000"&gt;http://localhost:4000&lt;/a&gt; and click Send, the response body should show &lt;strong&gt;Hapi World!&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Create a mongoDB connection to the API, create a file database.js in the root directory of the app&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var Mongoose = require('mongoose');

//load database
Mongoose.connect('mongodb://localhost/hapijs-mongoose-restapi/');
var db = Mongoose.connection;

db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function callback() {
    console.log('Connection with database succeeded.');
});

exports.db = db;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and include the database.js in app.js&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js

const db = require('./database').db;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will connect to the mongoDB and then let’s create the mongoose schema model for our wolves, the models was placed in /models directory&lt;/p&gt;

&lt;h3&gt;
  
  
  THE WOLF MODEL
&lt;/h3&gt;

&lt;p&gt;the path to create the Wolf Model is — /hapijs-mongoose-restapi/models/Wolf.js&lt;/p&gt;

&lt;p&gt;The Wolf model will be just having the &lt;strong&gt;name&lt;/strong&gt; field where the SchemaType is String.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');
const Schema = mongoose.Schema;

var WolfSchema = new Schema({
    name: String
});

module.exports = mongoose.model('Wolf', WolfSchema);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;with the Wolf.js model created, require this in the app.js&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js

const Hapi = require('hapi');
const server = new Hapi.Server();
const db = require('./database').db;

...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The nodemon will be in action here, it will watch for you changes in any of the file in the app directory and restarts the server for you, no CTRL+C hazzle.&lt;/p&gt;

&lt;h3&gt;
  
  
  ROUTES — Default API Route
&lt;/h3&gt;

&lt;p&gt;URL — &lt;a href="http://localhost:4000/api"&gt;http://localhost:4000/api&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js

...

server.route({
    method: 'GET',
    path: '/api',
    handler: function (request, reply) {
        reply({'message': 'Hello, API!'});
    }
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  ROUTES
&lt;/h3&gt;

&lt;p&gt;Create a routes.js file and include that file in app.js&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// routes.js

module.exports = [];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;then include this routes.js into the app.js file&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js

…

const routes = require(‘./routes’);
server.route(routes);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  The GET Route — GETTING ALL WOLVES
&lt;/h3&gt;

&lt;p&gt;Require the Wolf model onto the router.js&lt;/p&gt;

&lt;p&gt;URL —&lt;a href="http://localhost:4000/api/wolves"&gt; http://localhost:4000/api/wolves&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// routes.js

const Wolf = require('./models/Wolf');

module.exports = [
  {
      method: 'GET',
      path: '/api/wolves',
      handler: function (request, reply) {
          Wolf.find(function(error, wolves) {
              if (error) {
                  console.error(error);
              }

              reply(wolves);
          });
      }
  }
];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is a simple route — which will render all the wolves in JSON format.&lt;/p&gt;

&lt;h3&gt;
  
  
  The POST Route — SAVING A WOLF
&lt;/h3&gt;

&lt;p&gt;In the routes.js, create a module for POST which is for saving the Wolf&lt;/p&gt;

&lt;p&gt;URL —&lt;a href="http://localhost:4000/api/wolves/GrayWolf"&gt; http://localhost:4000/api/wolves/GrayWolf&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// routes.js

const Wolf = require('./models/Wolf');

module.exports = [
  {
      method: 'GET',
      path: '/api/wolves',
      handler: function (request, reply) {
          Wolf.find(function(error, wolves) {
              ...
          });
      }
  },
  {
      method: ['PUT', 'POST'],
      path: '/api/wolves/{name}',
      handler: function (request, reply) {          
          const wolf = new Wolf({
              name: request.params.name
          });
          wolf.save(function(error, wolf) {
            if (error) {
                console.error(error);
            }

            reply(wolf.id);
          });
      }
  }
];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will return the object id which is created in the mongoDB.&lt;/p&gt;

&lt;p&gt;You can find the source code &lt;a href="https://github.com/chetanraj/hapijs-mongoose-restapi"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We now have the ways to handle CRUD on Wolves using hapiJS.&lt;/p&gt;

&lt;p&gt;Please go js-rest-api on that heart icon which is below this post and if you have any questions please comment below.&lt;/p&gt;

</description>
      <category>api</category>
      <category>hapijs</category>
      <category>mongoose</category>
      <category>database</category>
    </item>
    <item>
      <title>Auto trigger manual deployment of Netlify with Siri</title>
      <dc:creator>Chetan</dc:creator>
      <pubDate>Tue, 25 Sep 2018 03:08:48 +0000</pubDate>
      <link>https://forem.com/chetan_raj/auto-trigger-manual-deployment-of-netlify-with-siri-5272</link>
      <guid>https://forem.com/chetan_raj/auto-trigger-manual-deployment-of-netlify-with-siri-5272</guid>
      <description>&lt;p&gt;Apple has released the latest iOS version — iOS 12 for iPhone on September 17th&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Also, Apple has released a new app &lt;a href="https://itunes.apple.com/us/app/workflow/id915249334?mt=8&amp;amp;pt=11l8808&amp;amp;ign-mpt=uo=4"&gt;Siri
Shortcuts&lt;/a&gt;,
which we’ll be using to trigger the manual deployment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8OxbtFNn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Awx6Tf9Y8R-nzU9WQHARLFg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8OxbtFNn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Awx6Tf9Y8R-nzU9WQHARLFg.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;small class="figcaption_hack"&gt;Photo Source —&lt;br&gt;
&lt;a href="https://unsplash.com/photos/04TYM24Wi2c"&gt;https://unsplash.com/photos/04TYM24Wi2c&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Firstly, create a build hook URL in your Netlify project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Goto — &lt;a href="https://app.netlify.com/sites/"&gt;https://app.netlify.com/sites/&lt;/a&gt;/settings/deploys&lt;/li&gt;
&lt;li&gt; Click on &lt;strong&gt;Add build hook&lt;/strong&gt; button, Enter the details&lt;/li&gt;
&lt;li&gt; Generate the &lt;strong&gt;Build hook url&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; Copy the &lt;strong&gt;Build hook url&lt;/strong&gt; - &lt;a href="https://api.netlify.com/build_hooks/"&gt;https://api.netlify.com/build_hooks/&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Launch Shortcuts app&lt;/p&gt;

&lt;p&gt;Step 1: Create Shortcut&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JZFLctVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AOXsXU-S8QtEUe1RPB8VBDA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JZFLctVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AOXsXU-S8QtEUe1RPB8VBDA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 2: Click on the settings icon on the top right and enter the name and then&lt;br&gt;
click on Done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZH3hqfsk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AN7vN55x4ZE1vAaYjpbplrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZH3hqfsk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AN7vN55x4ZE1vAaYjpbplrw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 3: Search for &lt;strong&gt;URL&lt;/strong&gt; and then enter the Netlify build hook URL of your app&lt;br&gt;
in the text as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aOI7vhlC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AgvElSG5dtei7f091L_Wcug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aOI7vhlC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AgvElSG5dtei7f091L_Wcug.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 4: Search for &lt;strong&gt;Get Contents of URL&lt;/strong&gt;, change the method type to **POST&lt;br&gt;
**as shown in the screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1yb1_pvG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AoljssYZ9KvLHOVTb0pcZiA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1yb1_pvG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2AoljssYZ9KvLHOVTb0pcZiA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ask Siri&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Trigger Netlify Deployment&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>showdev</category>
      <category>siri</category>
      <category>cicd</category>
      <category>netlify</category>
    </item>
  </channel>
</rss>
