<?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: Sanket Patel</title>
    <description>The latest articles on DEV Community by Sanket Patel (@3sanket3).</description>
    <link>https://dev.to/3sanket3</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%2F77544%2F4716c460-bfd2-4609-85fe-5e735bf1a7af.jpeg</url>
      <title>DEV Community: Sanket Patel</title>
      <link>https://dev.to/3sanket3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/3sanket3"/>
    <language>en</language>
    <item>
      <title>`useWindowSize` React Hook To Handle Responsiveness In JavaScript</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Thu, 05 Mar 2020 09:39:58 +0000</pubDate>
      <link>https://dev.to/3sanket3/usewindowsize-react-hook-to-handle-responsiveness-in-javascript-3dcl</link>
      <guid>https://dev.to/3sanket3/usewindowsize-react-hook-to-handle-responsiveness-in-javascript-3dcl</guid>
      <description>&lt;p&gt;It is sometimes helpful to know the responsive breakpoints in JavaScript to tweak and run the logic depending on the screen size.&lt;/p&gt;

&lt;p&gt;We will be creating a &lt;a href="https://reactjs.org/docs/hooks-custom.html" rel="noopener noreferrer"&gt;Custom React Hook&lt;/a&gt;. It will determine the screen size. And, we will be able to use the screen sizes just like we do in CSS media queries to update the UI or make the logic run a specific way.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The code is dependent on the &lt;code&gt;window&lt;/code&gt; object of the browser. The solution won't work in case of server-side rendering where the &lt;code&gt;window&lt;/code&gt; object won't exist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will name the custom hook &lt;code&gt;useWindowSize&lt;/code&gt;. We will have a state variable called &lt;code&gt;windowSize&lt;/code&gt; which will be exported to be used by React Components.&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;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="c1"&gt;//code to determine the screen size will go here&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt;

  &lt;span class="c1"&gt;//expose windowSize variable to be used by Components&lt;/span&gt;
  &lt;span class="c1"&gt;// to make responsiveness related chanegs&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now to determine the screen size, we will first check if the client is a browser, by checking if we have access to &lt;code&gt;window&lt;/code&gt; object. If we have, we can get the width of the screen using &lt;code&gt;window.innerWidth&lt;/code&gt; and assign into the state variable as default value.&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;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//👇&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isWindowClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;isWindowClient&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;//☝️&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;You can use this hook in the component as below,&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="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&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;useWindowSize&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./useWindowSize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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;windowSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;30px&lt;/span&gt;&lt;span class="dl"&gt;"&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;windowSize&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;&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%2Fzwjsrl3pq9g80hrtzfcp.gif" 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%2Fzwjsrl3pq9g80hrtzfcp.gif" alt="static width gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, on resize of the window, this hook won't inform us about the change in size(as shown above gif). To achieve it, we will have to implement &lt;code&gt;window&lt;/code&gt;'s on &lt;code&gt;resize&lt;/code&gt; listener. We will use it in &lt;code&gt;useEffect&lt;/code&gt; so that we won't register the listener each time it renders and we make sure that it gets unregistered when it needs to.&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;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&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;isWindowClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;isWindowClient&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;//👇&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&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="c1"&gt;//a handler which will be called on change of the screen resize&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setSize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&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="nx"&gt;isWindowClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//register the window resize listener&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

      &lt;span class="c1"&gt;//un-register the listener&lt;/span&gt;
      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSize&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="nx"&gt;isWindowClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="c1"&gt;//☝️&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&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%2Fi%2Fq806dpp0n9znes6nb9zb.gif" 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%2Fq806dpp0n9znes6nb9zb.gif" alt="dynamic width gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we want to have breakpoints instead of this absolute widths, we can convert the sizes into specific breakpoints (let say &lt;code&gt;sm&lt;/code&gt;, &lt;code&gt;md&lt;/code&gt;, &lt;code&gt;lg&lt;/code&gt;, &lt;code&gt;xlg&lt;/code&gt;) using a simple util function.&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;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&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="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//👇&lt;/span&gt;
&lt;span class="c1"&gt;//a Util function that will conver the absolute width into breakpoints&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getBreakPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;windowWidth&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="nx"&gt;windowWidth&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="nx"&gt;windowWidth&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;480&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;sm&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="k"&gt;else&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;windowWidth&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1024&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;md&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="k"&gt;else&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;windowWidth&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1200&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;lg&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="k"&gt;else&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;xlg&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="k"&gt;else&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;undefined&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="c1"&gt;//☝️&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&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;isWindowClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;isWindowClient&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;getBreakPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//👈&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&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="c1"&gt;//a handler which will be called on change of the screen resize&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setSize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getBreakPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&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="nx"&gt;isWindowClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//register the window resize listener&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

      &lt;span class="c1"&gt;//unregister the listerner on destroy of the hook&lt;/span&gt;
      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSize&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="nx"&gt;isWindowClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&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;windowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&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%2Fi%2Fkt43exylv0m5xtimvmzn.gif" 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%2Fkt43exylv0m5xtimvmzn.gif" alt="with breakpoint gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The codesandbox of the final code is below&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/funny-taussig-krsgn"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;All the best for making your users happy with all size of devices! 😄&lt;/p&gt;

&lt;p&gt;Cover Photo by &lt;a href="https://unsplash.com/@halgatewood" rel="noopener noreferrer"&gt;Hal Gatewood&lt;/a&gt; on &lt;a href="https://unsplash.com/" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Running Out Of Free Build Minutes On Netlify? Try This.</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Sat, 22 Feb 2020 18:09:47 +0000</pubDate>
      <link>https://dev.to/3sanket3/running-out-of-free-build-minutes-on-netlify-try-this-3lh9</link>
      <guid>https://dev.to/3sanket3/running-out-of-free-build-minutes-on-netlify-try-this-3lh9</guid>
      <description>&lt;h1&gt;
  
  
  Short Answer
&lt;/h1&gt;

&lt;p&gt;The Netlify provide a feature called Build Hooks. It is a URL, which we can hit via &lt;code&gt;curl&lt;/code&gt; to trigger deployment for the specific branch.&lt;/p&gt;

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

&lt;h1&gt;
  
  
  Long Answer
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What is Netlify?
&lt;/h2&gt;

&lt;p&gt;It is a great service to configure and deploy our web apps in no-time. The UI, features and their reliability everything is so slick. They are now not only the deployment solution but also expanding towards serverless functions, auth, storage, analytics and many more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is build minutes?
&lt;/h2&gt;

&lt;p&gt;The computation time(in minutes) on Netlify Server to build your app and generate the production files during deployment. On free plan netlify provides 300 free build minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem : They may fall short?
&lt;/h2&gt;

&lt;p&gt;Many times we need to have our development going on in several branches. If we have multiple developers working on the project, we generally keep pushing the code frequently. And if the changes on these branches need to reviewed, we configure them as continuous deployment. So with each push, if your branches are deployed, you may cross the 300 free minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;One of the awesome feature Netlify provides is deploy via calling a build hook. It is nothing but a URL which we should hit or run &lt;code&gt;curl&lt;/code&gt; on it to trigger the deployment of the branch. And this is really helpful as except production we are generally okay not to deploy the branches on each push. These command will make our code deployment on-demand and will save the build minutes.&lt;/p&gt;

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

&lt;p&gt;To keep them handy, we can configure it to the script section of &lt;code&gt;package.json&lt;/code&gt; as below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
"scripts": {
    "start": "&amp;lt;start command&amp;gt;",
    "deploy-dev": "curl -X POST -d {} https://api.netlify.com/build_hooks/5e3d300exxxxxxxca2246926", //&amp;lt;--
    "test": "&amp;lt;test command&amp;gt;",
}
....
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you think the non-master branches are unnecessarily using the build minutes and you are running out of free quota just due to that, you should use build hooks.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Few Awesome CSS Snippets I Recently Learned</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Thu, 31 Oct 2019 14:15:18 +0000</pubDate>
      <link>https://dev.to/3sanket3/few-awesome-css-snippets-i-recently-learned-33pb</link>
      <guid>https://dev.to/3sanket3/few-awesome-css-snippets-i-recently-learned-33pb</guid>
      <description>&lt;h1&gt;
  
  
  Center the absolute positioned content
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.center&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;-50%&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;Codepen: &lt;a href="https://codepen.io/3sanket3/pen/LYYOWwV"&gt;https://codepen.io/3sanket3/pen/LYYOWwV&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Maintain aspect ratio of the container
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;56.4%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* aspect ratio 16:9*/&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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



&lt;p&gt;The percentage should be calculated as: 16:9(w:h) = h*100/w =&amp;gt; 56.25%. Similarly,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1:1 =&amp;gt; 100%&lt;/li&gt;
&lt;li&gt;4:3 =&amp;gt; 75%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Codepen: &lt;a href="https://codepen.io/3sanket3/pen/dyyZWMX"&gt;https://codepen.io/3sanket3/pen/dyyZWMX&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Truncate the text
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.truncate&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;white-space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;nowrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ellipsis&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;Codepen : &lt;a href="https://codepen.io/3sanket3/pen/OJJOmqB"&gt;https://codepen.io/3sanket3/pen/OJJOmqB&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Set width as the available rest of the space
&lt;/h1&gt;

&lt;p&gt;It is useful when you have two adjacent containers. One has a fixed width and the other one should adjust according to the available remaining space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.fix-width-container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.adjustable-container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%-200px&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;h3&gt;
  
  
  Using CSS Variable
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;Declaring&lt;/span&gt; &lt;span class="nt"&gt;variable&lt;/span&gt; &lt;span class="nt"&gt;at&lt;/span&gt; &lt;span class="nt"&gt;root&lt;/span&gt; &lt;span class="nt"&gt;level&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;you&lt;/span&gt; &lt;span class="nt"&gt;can&lt;/span&gt; &lt;span class="nt"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;it&lt;/span&gt; &lt;span class="nt"&gt;at&lt;/span&gt; &lt;span class="nt"&gt;common&lt;/span&gt; &lt;span class="nt"&gt;parent&lt;/span&gt; &lt;span class="nt"&gt;level&lt;/span&gt;
&lt;span class="nd"&gt;:root&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--left-pane-width&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.fix-width-container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--left-pane-width&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.adjustable-container&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="n"&gt;-var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--left-pane-width&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;Codepen: &lt;a href="https://codepen.io/3sanket3/pen/qBBVjgy"&gt;https://codepen.io/3sanket3/pen/qBBVjgy&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Preserve line breaks in the preview
&lt;/h1&gt;

&lt;p&gt;It is useful when we want to show a preview of the content user entered in let say &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.preview&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;white-space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pre-line&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;CSS is something, which has no ends of learning. I would love to learn if you have such interesting snippets or links.&lt;/p&gt;

&lt;p&gt;Icon Courtesy: &lt;a href="https://thenounproject.com/term/css/60411/"&gt;https://thenounproject.com/term/css/60411/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How To Give An Impactful Demo At A Talk</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Tue, 02 Jul 2019 13:04:57 +0000</pubDate>
      <link>https://dev.to/3sanket3/how-to-give-impactful-demo-at-a-talk-28ph</link>
      <guid>https://dev.to/3sanket3/how-to-give-impactful-demo-at-a-talk-28ph</guid>
      <description>&lt;p&gt;Giving code demo at a meetup is a crucial part. And if it goes wrong, it may put you in a tough situation. In addition, the demo should be something that the audience should find interesting, easy to understand and doable. I will explain a few tricks I am using while giving a demo and it's working so far.&lt;/p&gt;

&lt;h1&gt;
  
  
  Though minimal, it should be a practical application that the audience can relate to 🚗
&lt;/h1&gt;

&lt;p&gt;A demo should be relatable to the practical scenario most of our audience are aware of.&lt;/p&gt;

&lt;p&gt;Also, they should feel like, they can do it with little effort, and for that,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Try to make it easily understandable. You can show an architecture diagram to give an overall idea&lt;/li&gt;
&lt;li&gt;Use third-party services/libraries so that users try to focus on the core concept and not additionally required supportive code&lt;/li&gt;
&lt;li&gt;Keep a very simple file structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Code from Scratch 🐣
&lt;/h1&gt;

&lt;p&gt;I found, if we start our demo from creating a project folder itself, the audience feels like no magic going on.&lt;/p&gt;

&lt;p&gt;If you are using frameworks, yes you may not want to spend time on long-running scaffolding process. In that case, if you can start from the default scaffolded files itself it would be great. If you need some utilities by default, you can create a package or at least separate folder which audience can consider a third party library and not focus on its implementation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Use third-party services 👨‍🔧
&lt;/h1&gt;

&lt;p&gt;When we are making demo practical, we may need third-party services like send an email, upload image, pull JSON data of specific business etc. Nowadays in the growing era of &lt;em&gt;No Code&lt;/em&gt; solutions, most of such services come with easy integration. So, better we quickly add them and try to make demo as real application as possible.&lt;/p&gt;

&lt;p&gt;The services mostly have with free quota limits so just make sure you don't exceed the same during demo itself 😉 I experienced it once 😅&lt;/p&gt;

&lt;h1&gt;
  
  
  Audience should feel like it will be doable 😎
&lt;/h1&gt;

&lt;p&gt;The actual success of the demo is when your audience tries it out and can implement themselves what you taught. And they will only try if they find it doable. Obviously, there can be people with a variety of experience level. But we should try to make it feel as easy as possible.&lt;/p&gt;

&lt;h1&gt;
  
  
  Keep some contents in mind to fill-in while waiting for long running tasks 📄
&lt;/h1&gt;

&lt;p&gt;There may be some tasks during demo which may take time like, stop and start the project, deployment, downloading libraries etc. While waiting for those process to complete, we can explain related concepts. So keep some content for the same. &lt;/p&gt;

&lt;h1&gt;
  
  
  Practice, Practice and Practice 👩‍💻
&lt;/h1&gt;

&lt;p&gt;Practice can only make you write the code quickly with less error. There will be many scenarios that you may fall into which you might not have given thought. By practicing more, you will come across them and get clear before the actual demo. Also, as I suggested in &lt;a href="https://dev.to/3sanket3/preparing-your-first-talk-5emg"&gt;preparing your first talk&lt;/a&gt;, you can give a demo to your friends and get feedback.&lt;/p&gt;

&lt;h1&gt;
  
  
  Keep screen recording as backup 📹
&lt;/h1&gt;

&lt;p&gt;We all know, it's programming! If unfortunately you run into an unexpected situation and getting out of it in limited time is not possible, you can explain the demo from screen recording.&lt;/p&gt;

&lt;p&gt;Hope you find them useful. Please add your suggestions as well in the comment. I would love to learn from your experience.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>Preparing Your First Talk</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Thu, 13 Jun 2019 12:20:48 +0000</pubDate>
      <link>https://dev.to/3sanket3/preparing-your-first-talk-5emg</link>
      <guid>https://dev.to/3sanket3/preparing-your-first-talk-5emg</guid>
      <description>&lt;p&gt;With this post, I wanted to share my experience of preparing for the talk and things to consider while delivering it.&lt;/p&gt;

&lt;p&gt;The target audience of the post is the developers planning to speak for the first time or have just started speaking in meetups or conferences.&lt;/p&gt;

&lt;p&gt;The frequent speaker may possibly get very few things out of this post. But, we would like to learn from your experience on the same. Please do share and guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  You don't have to be an expert 😎
&lt;/h2&gt;

&lt;p&gt;Yes, you should be prepared well and try to justify the amount of time your audience is spending on you. But, you don't have to be an expert.&lt;/p&gt;

&lt;p&gt;Sometimes you may not be working on a topic you are going to deliver in your regular project. In such case, try to be aware of the surroundings of your topic at least before a few weeks of delivery. Try to do as many examples as possible. Check out practical solutions and case studies.&lt;/p&gt;

&lt;p&gt;It may be possible that you may not be able to answer some of the questions from the audience, but that's fine. You can throw back to the audience. Or, you can get the contact of the person asking, come home, research and reply.&lt;/p&gt;

&lt;h2&gt;
  
  
  There can be an open discussion topic instead of in-depth on a single topic 👐
&lt;/h2&gt;

&lt;p&gt;We just started &lt;a href="https://www.meetup.com/surat-javascript-group/"&gt;a meetup group in Surat, India&lt;/a&gt;. During our first meetup, we were not sure which topic the local community would like out of the huge JavaScript eco-system. So, we kept it as an open discussion. Two of us covered various areas of JavaScript briefly and tried to put open to the audience to discuss them.&lt;/p&gt;

&lt;p&gt;We found it really helpful, as the first-timers were able to focus on &lt;em&gt;come out and speak&lt;/em&gt; instead of worrying about in-depth technical knowledge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pairing with someone 👭
&lt;/h2&gt;

&lt;p&gt;It is helpful to gain confidence at the same time, the in-between breaks help you to settle and start afresh with the next topic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice by giving demo talks to your friends 👨‍🏫
&lt;/h2&gt;

&lt;p&gt;This will immensely necessary to practice your talk and get it reviewed. If possible, you can try to give a demo to the friends having a different technology and level of experience. It will make your content perfect for the variety of audiences you are actually going to have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice your code a lot 👨‍💻
&lt;/h2&gt;

&lt;p&gt;If you are going to do live coding(which you should), better you practice at least 3-4 times. That way you can train your subconscious mind for making fewer mistakes even during the nervousness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audience learns more if you make mistakes while live coding 🐛
&lt;/h2&gt;

&lt;p&gt;From the mistakes you do while live coding, the audience will learn the complex cases. So don't worry about the mistakes. In addition to that, you are doing pair programming with the whole audience. There are chances they may help you if you get stuck.&lt;/p&gt;

&lt;p&gt;Just make sure you are clear with the concepts and have enough practice, so that mistakes may not completely block you and take huge time.&lt;/p&gt;

&lt;p&gt;Alternatively, you can also screen record your coding in advance and keep with you, which may help as a rescue if anything goes worst.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the Bio of your social accounts up to date 💄
&lt;/h2&gt;

&lt;p&gt;You will be one of the heroes of the meetup/conf. It's likely that people will try to find you on the internet. Better you show them the latest info.&lt;/p&gt;

&lt;h2&gt;
  
  
  You have a chance for marketing 📢
&lt;/h2&gt;

&lt;p&gt;If you are building a product, contributing to open source, starting a newsletter, designing course or doing anything exciting, people are there to hear about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be kind and show gratitude 🙏
&lt;/h2&gt;

&lt;p&gt;Show gratitude to the organizing team for giving you an opportunity to be there as a speaker.&lt;/p&gt;

&lt;p&gt;In addition, you can also thank the services you have used in your presentations for free. It may be a free PPT template, images, gifs or anything else. It will help those services to reach more audiences and ultimately make it better.&lt;/p&gt;

&lt;p&gt;Hope you find this helpful. Also, add your suggestions in the comment for me and others to learn from your experience.&lt;/p&gt;

&lt;p&gt;Cover image icon &lt;a href="https://thenounproject.com/search/?q=presentation&amp;amp;i=1724994"&gt;by Adrien Coquet from the Noun Project&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>Serverless FAQs</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Wed, 05 Jun 2019 11:39:55 +0000</pubDate>
      <link>https://dev.to/3sanket3/serverless-faqs-akl</link>
      <guid>https://dev.to/3sanket3/serverless-faqs-akl</guid>
      <description>&lt;h2&gt;
  
  
  No Servers? Really? 😲
&lt;/h2&gt;

&lt;p&gt;Haha, don't go with the literal meaning of the name. There are servers 🤦‍, just you won't have to manage the way you typically do. The cloud providers will dynamically manage the allocation of resources.&lt;/p&gt;

&lt;p&gt;You just write functions and deploy to the cloud. The cloud providers will store your functions in storage. When you ask to run the function, they will pull from storage, run it and done.&lt;/p&gt;

&lt;h2&gt;
  
  
  How will I be charged? 💸
&lt;/h2&gt;

&lt;p&gt;It will only charge for the computing time of your function. So, no charge when your code is not running 🤑&lt;/p&gt;

&lt;h2&gt;
  
  
  Does it support my programming language? 👨‍💻
&lt;/h2&gt;

&lt;p&gt;It depends on the cloud providers. Here is list of languages supported by the cloud providers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/lambda/"&gt;&lt;strong&gt;AWS:&lt;/strong&gt;&lt;/a&gt; Java, Go, PowerShell, Node.js, C#, Python, and Ruby&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cloud.google.com/functions/"&gt;&lt;strong&gt;Google Cloud:&lt;/strong&gt;&lt;/a&gt; Go, Node.js, Python&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://azure.microsoft.com/en-in/services/functions/"&gt;&lt;strong&gt;Azure:&lt;/strong&gt;&lt;/a&gt; PowerShell, Node.js, C#, Python, F#, Java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many other cloud providers that support running serverless functions like &lt;a href="https://www.cloudflare.com/en-in/products/cloudflare-workers/"&gt;Cloudflare&lt;/a&gt;, &lt;a href="https://www.ibm.com/in-en/cloud/functions"&gt;IBM Openwhisks&lt;/a&gt;, &lt;a href="https://kubeless.io/"&gt;Kubeless&lt;/a&gt;, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do I have the flexibility to use any version of the runtime environment? 👩‍🔧
&lt;/h2&gt;

&lt;p&gt;No, your code will run on the versions they support. You can find the supported version from the respective providers' documentation. Like, for AWS you can find &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Any framework that guides me writing serverless functions or the project? 👨‍🏫
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://serverless.com"&gt;https://serverless.com&lt;/a&gt;, is provider agnostic and supports most of the languages.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://claudiajs.com/"&gt;https://claudiajs.com/&lt;/a&gt; for JavaScript&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.zappa.io/"&gt;https://www.zappa.io/&lt;/a&gt; for Python&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html"&gt;Serverless Application Model&lt;/a&gt; for the AWS ecosystem&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://serverlesslibrary.net"&gt;https://serverlesslibrary.net&lt;/a&gt; : libraries by Azure Serverless Community &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If servers run on request instead of being ready all the time, won't it take time to respond to my request? 😴
&lt;/h2&gt;

&lt;p&gt;Yes, you may experience latency when you trigger a function.&lt;/p&gt;

&lt;p&gt;When you call the function for the first time, it takes time to set up the container and bootstrap the application. It is called a "cold start". But for subsequent requests, the cloud provider tries to reuse the container. And it depends on cloud providers and other infrastructure factors for how much time it will keep the containers live. So, they always advise writing code in a way that doesn't assume the container will be reused.&lt;/p&gt;

&lt;p&gt;The 'cold start' time depends on various factors like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Programming language - statically typed language takes more time&lt;/li&gt;
&lt;li&gt;When you update the functions and deploy, it destroys the containers&lt;/li&gt;
&lt;li&gt;How frequently your function is being called and keep the container "warm".&lt;/li&gt;
&lt;li&gt;The code size, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is not a huge problem in most of the cases. But still, if you want to avoid the cold start, you can schedule one function which keeps calling the function you want to keep warm, after every certain amount of time.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to trigger the deployed functions? ⚡️
&lt;/h2&gt;

&lt;p&gt;They can be triggered in many ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once deployed, you will get a dedicated HTTP URL, using which we can call&lt;/li&gt;
&lt;li&gt;You can configure the HTTP URLs to use as a REST Apis&lt;/li&gt;
&lt;li&gt;The function can be scheduled to run at a specific time&lt;/li&gt;
&lt;li&gt;On other cloud infrastructure events like on data change event of storage, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Are there examples, enjoying being serverless? 😎
&lt;/h2&gt;

&lt;p&gt;You can find case studies managed by frameworks and cloud providers like &lt;a href="https://serverless.com/learn/case-studies/"&gt;case studies by serverless framework&lt;/a&gt; and &lt;a href="https://aws.amazon.com/lambda/resources/customer-case-studies/"&gt;by AWS Lambda&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would recommend, you start to experiment with serverless if you haven't already. The easiest way is, making the backend functions of your side projects, serverless. And if you are yet to implement your first idea, the serverless will really helpful to remove the server management headache and ship your idea quickly 🚀&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>beginners</category>
      <category>aws</category>
      <category>azure</category>
    </item>
    <item>
      <title>Api Key Authentication for Accessing Serverless API at AWS API Gateway</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Fri, 31 May 2019 12:42:59 +0000</pubDate>
      <link>https://dev.to/3sanket3/api-key-authentication-for-accessing-serverless-api-at-aws-api-gateway-lfd</link>
      <guid>https://dev.to/3sanket3/api-key-authentication-for-accessing-serverless-api-at-aws-api-gateway-lfd</guid>
      <description>&lt;p&gt;Any REST API should set up some or the other authentication mechanism to secure from unintended uses. The AWS console and Serverless configuration provide an easy way to secure the API endpoints by setting up the API keys.&lt;/p&gt;

&lt;p&gt;I am assuming you already have basic idea about the Serverless Framework and setting up API Gateways for Serverless functions. If not, please quickly check my &lt;a href="https://dev.to/3sanket3/how-to-create-serverless-api-functions-with-aws-lambda-4k8m"&gt;relevant post&lt;/a&gt; once.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, make the endpoints private
&lt;/h2&gt;

&lt;p&gt;Set &lt;code&gt;private: true&lt;/code&gt; in the &lt;code&gt;http&lt;/code&gt; section of individual functions as follow.&lt;/p&gt;

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

&lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;handler.hello&lt;/span&gt;
    &lt;span class="na"&gt;events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hello&lt;/span&gt;
          &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;get&lt;/span&gt;
          &lt;span class="na"&gt;private&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  List the API key names in serverless.yml
&lt;/h2&gt;

&lt;p&gt;List all the API key names for which we want to generate the api keys, in &lt;code&gt;provider&lt;/code&gt; section of &lt;code&gt;serverless.yml&lt;/code&gt; as shown below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;apiKeys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientOne&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientTwo&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;The AWS will generate the actual keys for for each names we provided. The keys will be displayed in the output of &lt;code&gt;sls deploy&lt;/code&gt; command.&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%2Fdkwm1q4ovhjbx9hahjbo.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%2Fdkwm1q4ovhjbx9hahjbo.png" alt="specifying only api key names"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  If you explicitly want to specify the API key
&lt;/h2&gt;

&lt;p&gt;You set your own API key value by specifying &lt;code&gt;value&lt;/code&gt; property as below. It should be a string with a minimum length of 20. Optionally you can also provide a description to the value.&lt;/p&gt;

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

&lt;span class="na"&gt;apiKeys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientOne&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientTwo&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myClientThirdValueOfMinLength20&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;This is explicitly provided api key&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Deploy the changes by running &lt;code&gt;sls deploy&lt;/code&gt;, the AWS will auto-generate the name of the api key and set the provided value&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%2Fdpifm87uxkqsb9vgy4u0.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%2Fdpifm87uxkqsb9vgy4u0.png" alt="explicitly assigned value"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The below example will set both name and value explicitly&lt;/p&gt;

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

&lt;span class="na"&gt;apiKeys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myClientFour&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myClientFourValueOfR@n0mStr1n6&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Append the stage to the API key name
&lt;/h2&gt;

&lt;p&gt;The API keys are stored globally. So, it is advisable to append the stage name with API key name, if clients are allowed to access the multiple stages.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;apiKeys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;${self:provider.stage}-myClientFive&lt;/span&gt;


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

&lt;/div&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%2Fau820hz8jlrecj27zha6.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%2Fau820hz8jlrecj27zha6.png" alt="specify stage in api key name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same way if you want to use the environment variable you can do it by &lt;code&gt;${self:provider.environment.YOUR_ENV_VARIABLE}&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each time we make any change in &lt;code&gt;serverless.yml&lt;/code&gt;, we should deploy using &lt;code&gt;sls deploy&lt;/code&gt; to have its effect on AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; You can use &lt;code&gt;sls print&lt;/code&gt; command to review the compiled yaml configuration file before running &lt;code&gt;sls deploy&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Set quota limits
&lt;/h2&gt;

&lt;p&gt;We can set the quota limits to the API as follow&lt;/p&gt;

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

&lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="s"&gt;usagePlan&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;quota&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5000&lt;/span&gt;
      &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
      &lt;span class="na"&gt;period&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MONTH&lt;/span&gt;
    &lt;span class="na"&gt;throttle&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;burstLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;
      &lt;span class="na"&gt;rateLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;We can even categorize the quota, for example, &lt;em&gt;free&lt;/em&gt; and &lt;em&gt;paid&lt;/em&gt;. We should assign the api keys to the respective categories.&lt;/p&gt;

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

&lt;span class="na"&gt;apiKeys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;free&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientOne&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;myClientTwo&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;paid&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myClientThirdValueOfMinLength20&lt;/span&gt;
        &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;This is explicitly provided api key&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;${self:provider.stage}-myClientFive&lt;/span&gt;

&lt;span class="na"&gt;usagePlan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;free&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;quota&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5000&lt;/span&gt;
        &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
        &lt;span class="na"&gt;period&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MONTH&lt;/span&gt;
      &lt;span class="na"&gt;throttle&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;burstLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;
        &lt;span class="na"&gt;rateLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;paid&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;quota&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50000&lt;/span&gt;
        &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
        &lt;span class="na"&gt;period&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MONTH&lt;/span&gt;
      &lt;span class="na"&gt;throttle&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;burstLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2000&lt;/span&gt;
        &lt;span class="na"&gt;rateLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;All the configuration we did here, can be seen at &lt;a href="https://console.aws.amazon.com/apigateway/home?region=us-east-1" rel="noopener noreferrer"&gt;API Gateway service of AWS Console&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you find the same helpful.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;You can find the code explained here at &lt;a href="https://github.com/3sanket3/serverless-aws-api-gateway" rel="noopener noreferrer"&gt;https://github.com/3sanket3/serverless-aws-api-gateway&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;p&gt;Reference: &lt;a href="https://serverless.com/framework/docs/providers/aws/events/apigateway/#setting-api-keys-for-your-rest-api" rel="noopener noreferrer"&gt;https://serverless.com/framework/docs/providers/aws/events/apigateway/#setting-api-keys-for-your-rest-api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image Credits :  &lt;a href="https://thenounproject.com/search/?q=ticket&amp;amp;i=1807395" rel="noopener noreferrer"&gt;Three Six Five&lt;/a&gt; and &lt;a href="https://worldvectorlogo.com/downloaded/aws-api-gateway" rel="noopener noreferrer"&gt;https://worldvectorlogo.com/downloaded/aws-api-gateway&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>node</category>
      <category>aws</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How To Create Serverless API Functions With AWS Lambda</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Tue, 21 May 2019 14:31:18 +0000</pubDate>
      <link>https://dev.to/3sanket3/how-to-create-serverless-api-functions-with-aws-lambda-4k8m</link>
      <guid>https://dev.to/3sanket3/how-to-create-serverless-api-functions-with-aws-lambda-4k8m</guid>
      <description>&lt;p&gt;In this tutorial, we will learn how to create the serverless API functions. We will be using the &lt;a href="https://serverless.com"&gt;serverless framework&lt;/a&gt; and host the functions to AWS Lambda.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wondering why serverless?
&lt;/h3&gt;

&lt;p&gt;Please check &lt;a href="https://aws.amazon.com/lambda/"&gt;AWS Lambda&lt;/a&gt; or Cloudflare's &lt;a href="https://www.cloudflare.com/learning/serverless/why-use-serverless/"&gt;why use serverless&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started
&lt;/h2&gt;

&lt;p&gt;Install the &lt;code&gt;serverless&lt;/code&gt; globally&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;-g&lt;/span&gt; serverless
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Check if it is installed by running &lt;code&gt;serverless -v&lt;/code&gt; command on terminal&lt;br&gt;
&lt;/p&gt;

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



&lt;h2&gt;
  
  
  Get the boilerplate
&lt;/h2&gt;

&lt;p&gt;We will use the &lt;em&gt;aws-nodejs&lt;/em&gt; template to create our service, let say with the name &lt;code&gt;testing-one&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sls create &lt;span class="nt"&gt;--template&lt;/span&gt; aws-nodejs &lt;span class="nt"&gt;--path&lt;/span&gt; testing-one
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;sls&lt;/code&gt; is a shortcut of &lt;code&gt;serverless&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The default template will have &lt;code&gt;handler.js&lt;/code&gt;. It contains a dummy function called &lt;code&gt;hello&lt;/code&gt;. The business logic should go inside it. In the next step, we will deploy the same function to AWS Lambda.&lt;/p&gt;

&lt;p&gt;Let's simplify the &lt;code&gt;hello&lt;/code&gt; function and return the &lt;code&gt;message&lt;/code&gt; as below:&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;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;event&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, there!`&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="kc"&gt;null&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="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy to AWS Lambda
&lt;/h2&gt;

&lt;p&gt;For deploying the functions to AWS, we need to set up credentials in our machine.&lt;/p&gt;

&lt;p&gt;If it is already set up in your machine, the below command should display the &lt;em&gt;access key id&lt;/em&gt; and &lt;em&gt;secret access key&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &amp;lt; ~/.aws/credentials

&lt;span class="o"&gt;[&lt;/span&gt;default]
aws_access_key_id &lt;span class="o"&gt;=&lt;/span&gt; your-access-key-id
aws_secret_access_key &lt;span class="o"&gt;=&lt;/span&gt; your-secret-access-key
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Else, please follow this &lt;a href="https://www.youtube.com/watch?v=KngM5bfpttA"&gt;video&lt;/a&gt;, to set up the AWS credentials.&lt;/p&gt;

&lt;p&gt;To deploy the function, run the &lt;code&gt;deploy&lt;/code&gt; command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sls deploy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you navigate to the AWS Lambda console (&lt;a href="https://console.aws.amazon.com"&gt;https://console.aws.amazon.com&lt;/a&gt; &amp;gt; Services &amp;gt; Lambda &amp;gt; Function), you will find the &lt;code&gt;hello&lt;/code&gt; function deployed there. (Make sure you have selected the correct region at top-right of the screen)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NachS-tR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/53xuqhvqz8rald35do32.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NachS-tR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/53xuqhvqz8rald35do32.PNG" alt="lambda console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function name &lt;code&gt;testing-one-dev-hello&lt;/code&gt; displayed is in the following format.&lt;/p&gt;

&lt;p&gt;&amp;lt; service name &amp;gt; - &amp;lt; stage &amp;gt; - &amp;lt; function name &amp;gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Invoke deployed function
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sls invoke &lt;span class="nt"&gt;-f&lt;/span&gt; hello

&lt;span class="o"&gt;{&lt;/span&gt;
 &lt;span class="s2"&gt;"statusCode"&lt;/span&gt;: 200,
 &lt;span class="s2"&gt;"body"&lt;/span&gt;: &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;  &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Hi, there!&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;-f&lt;/code&gt; is shorthand of &lt;code&gt;-function&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So the function &lt;code&gt;hello&lt;/code&gt; is deployed and running. Let's make it a REST API function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the function as REST API
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Events&lt;/em&gt; are the things that trigger your functions to run. One of such kind of event is HTTP event. The HTTP event can be generated by one of the HTTP endpoints.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating GET endpoint
&lt;/h3&gt;

&lt;p&gt;Let say we want to trigger the &lt;code&gt;hello&lt;/code&gt; function when a &lt;code&gt;GET&lt;/code&gt; HTTP request made to the path &lt;code&gt;/hello&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is, &lt;code&gt;GET : https://someurl.com/hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The file &lt;code&gt;serverless.yml&lt;/code&gt; is exactly for such kind of configuration in the serverless project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;YAML (.yml)&lt;/strong&gt; is a data-serialization language and used for configuration files. It's just like JSON but more human readable friendly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In &lt;code&gt;serverless.yml&lt;/code&gt;, change the &lt;code&gt;functions&lt;/code&gt; sections as shown below.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please ensure you have proper &lt;a href="https://www.tutorialspoint.com/yaml/yaml_basics.htm"&gt;indentation as per YAML standards&lt;/a&gt;. You can also learn by playing at &lt;a href="http://nodeca.github.io/js-yaml/"&gt;http://nodeca.github.io/js-yaml/&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;handler.hello&lt;/span&gt;
    &lt;span class="na"&gt;events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hello&lt;/span&gt;
          &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;get&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Deploy the changes
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;sls deploy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The deploy command output should return you the URL endpoints that we should use to trigger the function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ccIdUvHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gybrnub4sgwu6micu9up.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ccIdUvHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gybrnub4sgwu6micu9up.png" alt="lambda GET endpoints"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can browse the endpoint in the browser. It will hit the lambda function and will return the below result.&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;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hi, there!"&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;h3&gt;
  
  
  Accept Query String parameters
&lt;/h3&gt;

&lt;p&gt;You can also pass the query string parameters and process it in your business logic.&lt;/p&gt;

&lt;p&gt;Let's update the &lt;code&gt;hello&lt;/code&gt; function to process the &lt;code&gt;name&lt;/code&gt; parameter passed in as query string&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;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;event&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queryStringParameters&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queryStringParameters&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;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queryStringParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="kc"&gt;null&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="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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, there!`&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="kc"&gt;null&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="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 if you will hit the below URL, you should receive output as below&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://some-random-text.execute-api.us-east-1.amazonaws.com/dev/hello?name=Sanket&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;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hi, Sanket!"&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;h3&gt;
  
  
  Creating POST endpoint
&lt;/h3&gt;

&lt;p&gt;You can configure the function(let say &lt;code&gt;submitForm&lt;/code&gt;) as POST in &lt;code&gt;serverless.yml&lt;/code&gt; as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;handler.hello&lt;/span&gt;
    &lt;span class="na"&gt;events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hello&lt;/span&gt;
          &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;get&lt;/span&gt;
  &lt;span class="c1"&gt;# POST endpoint&lt;/span&gt;
  &lt;span class="na"&gt;submitForm&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;handler.submitForm&lt;/span&gt;
    &lt;span class="na"&gt;events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;submitForm&lt;/span&gt;
          &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;post&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;submitForm&lt;/code&gt; function will be&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;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;submitForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;event&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="kc"&gt;null&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="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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&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="s2"&gt;Received nothing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="kc"&gt;null&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="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;Deploy the service using &lt;code&gt;sls deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6pCfdzDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/s1z6toi0nxey2vxmbhkj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6pCfdzDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/s1z6toi0nxey2vxmbhkj.png" alt="lambda POST endpoints"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can POST the data to the endpoint using tools like &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt;. It should respond with the data sent in the body.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OVrJHY6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fiajnayofdp4ev0j84qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OVrJHY6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/fiajnayofdp4ev0j84qu.png" alt="postman"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it for now. I hope you find the tutorial helpful to get started using the serverless functions. &lt;/p&gt;

&lt;p&gt;You can find the code explained here at &lt;a href="https://github.com/3sanket3/serverless-aws-api-gateway"&gt;https://github.com/3sanket3/serverless-aws-api-gateway&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>aws</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How To Quickly Deploy Node Js App To Heroku</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Mon, 13 May 2019 14:05:06 +0000</pubDate>
      <link>https://dev.to/3sanket3/how-to-quickly-deploy-node-js-app-to-heroku-58k4</link>
      <guid>https://dev.to/3sanket3/how-to-quickly-deploy-node-js-app-to-heroku-58k4</guid>
      <description>&lt;p&gt;This tutorial will cover how to deploy the Node.js project to Heroku - the cloud application platform. We will have our application up by running few commands.&lt;/p&gt;

&lt;p&gt;Assuming you have any node.js app that you want to publish. If not, I have listed the steps in &lt;a href="https://3sanket3.com/posts/how-to-setup-basic-node-server" rel="noopener noreferrer"&gt;this tutorial&lt;/a&gt;. The codesandbox for the same is &lt;a href="https://codesandbox.io/embed/79wz0k0v1" rel="noopener noreferrer"&gt;here&lt;/a&gt; to set up the basic app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Git&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To use the Huroku CLI we will need to have the Git installed in the machine, so make sure you have it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;You can check if it is already installed or not using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nt"&gt;--version&lt;/span&gt;
    git version 2.18.0.windows.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Node 8+
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$ &lt;/span&gt;node &lt;span class="nt"&gt;--version&lt;/span&gt;
  v8.12.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;A registered account at &lt;a href="https://heroku.com" rel="noopener noreferrer"&gt;https://heroku.com&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Please sign up and verify your email address, if you haven't.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Initialize the Git for the project (if it isn't)
&lt;/h2&gt;

&lt;p&gt;If your project is the git repository itself then move to install heroku&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git init
Initialized empty Git repository &lt;span class="k"&gt;in &lt;/span&gt;your-project-path/.git/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;.gitignore&lt;/code&gt; file to ignore &lt;code&gt;node_modules&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;node_modules &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit the files to git repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nt"&gt;-A&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'initial commit'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;master &lt;span class="o"&gt;(&lt;/span&gt;root-commit&lt;span class="o"&gt;)&lt;/span&gt; e79168d] initial commit
 4 files changed, 2047 insertions&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;
 create mode 100644 .gitignore
 create mode 100644 index.js
 create mode 100644 package.json
 create mode 100644 yarn.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Heroku
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up" rel="noopener noreferrer"&gt;Download&lt;/a&gt; and install the Heroku CLI as per your platform.&lt;/p&gt;

&lt;p&gt;Check if it is installed by checking version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$ &lt;/span&gt;heroku &lt;span class="nt"&gt;--version&lt;/span&gt;
  heroku/7.24.3 win32-x64 node-v11.14.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Login to Heroku
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;heroku login&lt;/code&gt; command will ask us to open a browser using pressing any key. Then you can login in browser and the terminal will catch it. Isn't it cool!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;heroku login
heroku: Press any key to open up the browser to login or q to &lt;span class="nb"&gt;exit&lt;/span&gt;:
Opening browser to https://cli-auth.heroku.com/auth/browser/06c81181-c988-457f-b415-5789e7abd758
Logging &lt;span class="k"&gt;in&lt;/span&gt;... &lt;span class="k"&gt;done
&lt;/span&gt;Logged &lt;span class="k"&gt;in &lt;/span&gt;as 3sanket3@gmail.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a Heroku app
&lt;/h2&gt;

&lt;p&gt;Create the app using command &lt;code&gt;heroku create &amp;lt;optional-app-name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;heroku create nodejs-tutorial-one-3sanket3

Creating ⬢ nodejs-tutorial-one-3sanket3... &lt;span class="k"&gt;done
&lt;/span&gt;https://nodejs-tutorial-one-3sanket3.herokuapp.com/ | https://git.heroku.com/nodejs-tutorial-one-3sanket3.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Make sure the &lt;code&gt;package.json&lt;/code&gt; of your project have a &lt;code&gt;start&lt;/code&gt; command
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"scripts"&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;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodemon index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;--&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;development&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;purpose&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node ."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;--&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Heroku&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;will&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;start&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;application&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Error: no test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; exit 1"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: If you want to use &lt;code&gt;start&lt;/code&gt; command for some other task, you can create a &lt;code&gt;Procfile&lt;/code&gt; . It will tell Heroku which command to run while starting the application, as explained &lt;a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs#define-a-procfile" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Deploy the code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git push heroku master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything goes fine you should see the last part of the command output as below. It contains the URL at which your app is deployed.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foavbqxgphz9tx0lh396e.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foavbqxgphz9tx0lh396e.PNG" alt="heroku deployment output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check deployment logs
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;heroku logs --tail&lt;/code&gt; command, you can check logs of deployment. It will be updated realtime so you can keep it open while deployment, in another terminal tab/window keep your eye on it.&lt;/p&gt;

&lt;p&gt;Ref : &lt;a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs" rel="noopener noreferrer"&gt;https://devcenter.heroku.com/articles/getting-started-with-nodejs&lt;/a&gt;&lt;br&gt;
Cover Photo by &lt;a href="https://www.pexels.com/photo/silhouette-photo-of-man-throw-paper-plane-1262304/" rel="noopener noreferrer"&gt;Rakicevic Nenad from Pexels&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Extend 'pairing' to read docs and watch talks</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Thu, 14 Mar 2019 20:59:59 +0000</pubDate>
      <link>https://dev.to/3sanket3/extend-pairing-to-read-docs-and-watch-talks-28h7</link>
      <guid>https://dev.to/3sanket3/extend-pairing-to-read-docs-and-watch-talks-28h7</guid>
      <description>&lt;p&gt;Disclaimer : I am not a good story teller, so feel free to jump to the &lt;strong&gt;The Idea&lt;/strong&gt; direclty.&lt;/p&gt;

&lt;h3&gt;
  
  
  Story
&lt;/h3&gt;

&lt;p&gt;&lt;a class="comment-mentioned-user" href="https://dev.to/ron4ex"&gt;@ron4ex&lt;/a&gt;
 and I frequently reach to each other offline or via call, if we stuck somewhere or need another perceptive in our tasks. In which, the other guy doesn't necessarily have gone through the same scenario but helps the seeking one with one's view and knowledge base.&lt;/p&gt;

&lt;p&gt;Currently we both got to work on React + Firebase stack. Two days before, we discussed that each of our project needs a service to keep common firebase query related tasks in it. So we roughly decided the API of the same. And yesterday both of us worked to add that service in our respective project. &lt;/p&gt;

&lt;p&gt;Today we had a call to discuss the service. I found the discussion little different than usual. As we were working on same problem, during discussion we were able to share many cases/ideas/issues to make the service much better, which eventually may be a separate library. &lt;/p&gt;

&lt;p&gt;From the story above, I was thinking,&lt;/p&gt;

&lt;h3&gt;
  
  
  The Idea
&lt;/h3&gt;

&lt;p&gt;Let say to read a blog post like &lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;https://overreacted.io/a-complete-guide-to-useeffect/&lt;/a&gt; , if two guys sit an decide to read and understand individually. Then meet on a call to  discuss on it. What an amazing level of knowledge and understanding they both will get out of it.&lt;/p&gt;

&lt;p&gt;The same is applicable to do side projects in same tech-stack or to watch the conference talks.&lt;/p&gt;

&lt;p&gt;I am having below blog posts in my to do list to read and understand. Please let me know if anyone want to &lt;em&gt;pair&lt;/em&gt; with me for the same.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;https://overreacted.io/a-complete-guide-to-useeffect/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/hooks-overview.html"&gt;https://reactjs.org/docs/hooks-overview.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.robinwieruch.de/react-hooks-fetch-data/"&gt;https://www.robinwieruch.de/react-hooks-fetch-data/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/sw-yx/react-typescript-cheatsheet"&gt;https://github.com/sw-yx/react-typescript-cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>todayilearned</category>
      <category>productivity</category>
    </item>
    <item>
      <title>CRA typescript is compiling slow</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Thu, 14 Mar 2019 17:43:17 +0000</pubDate>
      <link>https://dev.to/3sanket3/cra-typescript-is-compiling-slow-595h</link>
      <guid>https://dev.to/3sanket3/cra-typescript-is-compiling-slow-595h</guid>
      <description>&lt;p&gt;CRA with typescript is bit slow even after &lt;code&gt;"skipLibCheck": true&lt;/code&gt;. Mostly I find hitting F5 better than waiting for the page to auto reload.&lt;/p&gt;

&lt;p&gt;Also the intellisense and error detection just stop working many times. I need to close the VS Code to get it fixed.&lt;/p&gt;

&lt;p&gt;Is there any config, extensions or anything can help for this?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

&lt;p&gt;CC: &lt;a class="comment-mentioned-user" href="https://dev.to/swyx"&gt;@swyx&lt;/a&gt;
&lt;/p&gt;

</description>
      <category>help</category>
      <category>typescript</category>
      <category>vscode</category>
      <category>react</category>
    </item>
    <item>
      <title>Is 20-20-20 👁️ or Pomodoro 🍅 not working for you? Try this.</title>
      <dc:creator>Sanket Patel</dc:creator>
      <pubDate>Tue, 29 Jan 2019 12:56:12 +0000</pubDate>
      <link>https://dev.to/3sanket3/is-20-20-20--or-pomodoro--not-working-for-you-try-this-4icg</link>
      <guid>https://dev.to/3sanket3/is-20-20-20--or-pomodoro--not-working-for-you-try-this-4icg</guid>
      <description>&lt;p&gt;Not sure why but both the techniques didn't work for me and I was in need of something that can force me to take a break.&lt;/p&gt;

&lt;p&gt;So I invented 😉 the following technique that works for me. It might sound funny but it's effective.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Drink 2-3* glasses of water 🥛🥛🥛 (or as many as possible)&lt;/li&gt;
&lt;li&gt;Start coding 💻&lt;/li&gt;
&lt;li&gt;You will need to pee in about 20-25* min, go and attend to it 🚽&lt;/li&gt;
&lt;li&gt;Repeat...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More water is healthier &lt;/li&gt;
&lt;li&gt;You will need to take a break&lt;/li&gt;
&lt;li&gt;You will need to leave your seat and walk &lt;/li&gt;
&lt;li&gt;Once done, you will feel relaxed and your mind will be at peace. It will help you with a fresh perspective on your work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;[EDIT] NOTE: By researching on&lt;/em&gt; &lt;a class="comment-mentioned-user" href="https://dev.to/simoroshka"&gt;@simoroshka&lt;/a&gt;
 &lt;em&gt;'s comment below, it is found that to urinate up to 10 times a day is okay, not more than that. More information is curated in the comment itself, I highly recommend you also check the same.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Give it a try! &lt;/p&gt;

&lt;p&gt;And yeah, any idea about what should I name this technique? 😂🤔&lt;/p&gt;

&lt;p&gt;Stay Productive, Stay Healthy!&lt;/p&gt;

&lt;p&gt;Proof read by &lt;a href="https://twitter.com/ron4ex"&gt;Ronak Baldha&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devtips</category>
      <category>health</category>
      <category>pomodoro</category>
    </item>
  </channel>
</rss>
