<?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: Sungmin</title>
    <description>The latest articles on DEV Community by Sungmin (@sungminkim0508).</description>
    <link>https://dev.to/sungminkim0508</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%2F230715%2Fc3989b95-1e14-42f8-99ed-c9cbec4e6595.png</url>
      <title>DEV Community: Sungmin</title>
      <link>https://dev.to/sungminkim0508</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sungminkim0508"/>
    <language>en</language>
    <item>
      <title>How to Set up Node.js with Typescript</title>
      <dc:creator>Sungmin</dc:creator>
      <pubDate>Wed, 30 Sep 2020 20:23:23 +0000</pubDate>
      <link>https://dev.to/sungminkim0508/how-to-set-up-node-js-with-typescript-4b4d</link>
      <guid>https://dev.to/sungminkim0508/how-to-set-up-node-js-with-typescript-4b4d</guid>
      <description>&lt;p&gt;First thing first, we need to install all packages for typescript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Packages
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; @types/node typescript
yarn add ts-node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@types/node&lt;/code&gt;: contains all type for Node.js.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;typescript&lt;/code&gt;: supports typescript on the app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ts-node&lt;/code&gt;: tool that read typescript files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add &lt;code&gt;start&lt;/code&gt; script on &lt;code&gt;package.json&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&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;"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;"ts-node src/index.ts"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to create &lt;code&gt;tsconfig.json&lt;/code&gt; to understand &lt;code&gt;.ts&lt;/code&gt; file and set up compiler options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will ask you what framework you are using. I will choose &lt;code&gt;node&lt;/code&gt;.&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%2Fi%2Fnhe7js7gff2l9i9immgh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnhe7js7gff2l9i9immgh.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's run typescript. We are going to run the &lt;code&gt;.ts&lt;/code&gt; file without transpiling. Create &lt;code&gt;src/index.ts&lt;/code&gt; and type like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// hello world&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and run command &lt;code&gt;yarn start&lt;/code&gt;. And you will see &lt;code&gt;hello world&lt;/code&gt; on the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add &lt;code&gt;tsc -w&lt;/code&gt; on package.json
&lt;/h2&gt;

&lt;p&gt;When you run typescript files, there are a coule of things you worry about&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compiler compiles typescript files and run the app, which it is slow to execute.&lt;/li&gt;
&lt;li&gt;You are not sure what bugs come out before you transpile &lt;code&gt;.ts&lt;/code&gt; especially when you build the production code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So what I am going to do is transpiling the &lt;code&gt;.ts&lt;/code&gt; to &lt;code&gt;.js&lt;/code&gt;, and run only &lt;code&gt;.js&lt;/code&gt; file, not &lt;code&gt;.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open package.json and add &lt;code&gt;watch&lt;/code&gt; flag&lt;br&gt;
&lt;/p&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="err"&gt;package.json&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;"watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc -w"&lt;/span&gt;&lt;span class="p"&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;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;tsc -w&lt;/code&gt; command is one of Typescript CLI command and simply transpiles &lt;code&gt;.ts&lt;/code&gt; files and generate &lt;code&gt;.js&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;But you need to tell Typescript CLI in which folders you are going to put &lt;code&gt;.js&lt;/code&gt; files transpiled by &lt;code&gt;tsc -w&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;So open &lt;code&gt;tsconfig.json&lt;/code&gt; and add option &lt;code&gt;"outDir": "./dist"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-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;"compilerOptions"&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;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"commonjs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="s2"&gt;"dom"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="s2"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="s2"&gt;"es2017"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="s2"&gt;"esnext.asynciterable"&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="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

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

&lt;/div&gt;



&lt;p&gt;You can change the directory whenever you want. You just change &lt;code&gt;"outDir": "yourDir"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Okay. Let's try this out. Open &lt;code&gt;package.json&lt;/code&gt; and add &lt;code&gt;dev&lt;/code&gt; script like this.&lt;br&gt;
&lt;/p&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="err"&gt;package.json&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;"watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc -w"&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;"node dist/index.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open two terminals and run &lt;code&gt;yarn watch&lt;/code&gt; and &lt;code&gt;yarn dev&lt;/code&gt;. And you will see compiler is running &lt;code&gt;.js&lt;/code&gt; files that transfiled from &lt;code&gt;.ts&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Learning Hapi.js (1) - How I feel when I learned Hapi.js for the first time</title>
      <dc:creator>Sungmin</dc:creator>
      <pubDate>Fri, 08 May 2020 01:23:33 +0000</pubDate>
      <link>https://dev.to/sungminkim0508/learning-hapi-js-1-how-i-feel-when-i-learned-hapi-js-for-the-first-time-4enf</link>
      <guid>https://dev.to/sungminkim0508/learning-hapi-js-1-how-i-feel-when-i-learned-hapi-js-for-the-first-time-4enf</guid>
      <description>&lt;h1&gt;
  
  
  Learning Hapi.js (1) - How I feel when I learned Hapi.js for the first time
&lt;/h1&gt;

&lt;p&gt;I've ever heard of a couple of Node.js Framework like Express.js and Koa.js, but I've never heard of Hapi.js before I start working for the current company. However, I feel like what Hapi.js looks like(I mean syntax) is similar to the syntax of Express.js and, just for my personal opinion, Hapi.js looks easier to read for me than Express.js. Because of several reasons, I would like to dive into Hapi.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Hapi.js?
&lt;/h2&gt;

&lt;p&gt;Hapi.js is an open-source framework like Express.js and Koa.js. It was created by the mobile team at Walmart Labs - led by Eran Hammer - to handle heavy traffic for events like Black Friday. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hapi.js?
&lt;/h2&gt;

&lt;p&gt;According to Eran Hammer, who is the creator of Hapi.js, there are several reasons why you consider Hapi.js (&lt;a href="https://hueniverse.com/why-you-should-consider-hapi-6163689bd7c2"&gt;Why you should consider Hapi.js&lt;/a&gt;)&lt;/p&gt;

&lt;h5&gt;
  
  
  Readability vs Performance
&lt;/h5&gt;

&lt;p&gt;Eran chooses the code &lt;strong&gt;readability&lt;/strong&gt; instead of the &lt;strong&gt;performance&lt;/strong&gt;. Readability and performance are in conflict. The performance keep getting better and faster as machines get improved. However, most issues were found and resolved easily since the codes kept being readable. This point lets him choose the code readability in terms of &lt;strong&gt;'Humans'&lt;/strong&gt; performance.&lt;/p&gt;

&lt;h5&gt;
  
  
  Minimal Dependencies
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;If you followed &lt;a href="https://github.com/dominictarr/event-stream/issues/116"&gt;recent news&lt;/a&gt;, this is a big deal&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;He created Hapi.js without any external dependencies except for one external dependency. I think he really cares about keeping Hapi.js to be maintainable and preventing it from being crashed down by external dependencies. He gives this &lt;a href="https://github.com/dominictarr/event-stream/issues/116"&gt;link&lt;/a&gt; and you feel why he considers not to introduce external dependencies.&lt;/p&gt;

&lt;h5&gt;
  
  
  100% Code Coverage and Style
&lt;/h5&gt;

&lt;p&gt;Hapi was required to have 100% test code coverage. Hapi Team wrote their own test code when existing test tools are not enough to cover. And they keep revising the style as better approaches are developed and all code bases are introduced with the new approaches.&lt;/p&gt;

&lt;h5&gt;
  
  
  Less Open Issues
&lt;/h5&gt;

&lt;p&gt;There are 27 modules for the entire framework. Except for Joi module, the rest of the modules have 6 open pull requests, 9 open reported issues and 19 open feature requests or questions. This is a significant low number of reporting issues. &lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Hapi.js and Express.js
&lt;/h2&gt;

&lt;p&gt;Since I have learned Express.js, my perspective was stick to Express.js syntax and had negative thoughts on learning new Node.js framework. But after I've learned Hapi, my perspective has changed in a good way.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Easier to read code
&lt;/h3&gt;

&lt;p&gt;I realize that Hapi.js is somewhat wordier than Express.js, but Hapi.js explicitly describes url, request method, request body, and params. This characteristic is powerful when APIs are getting growing and complex. Because we don't need to take a look at what query or request body looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="cm"&gt;/**
    Assuming that you create getUser() and loginUser() method.
  */&lt;/span&gt;

  &lt;span class="cm"&gt;/* #### Express.js #### */&lt;/span&gt;
  &lt;span class="c1"&gt;// GET /user&lt;/span&gt;
  &lt;span class="c1"&gt;// Params: id&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="cm"&gt;/* #### Hapi.js #### */&lt;/span&gt;
  &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="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="cm"&gt;/*  =======================================  */&lt;/span&gt;

  &lt;span class="cm"&gt;/*  #### Express.js #### */&lt;/span&gt;
  &lt;span class="c1"&gt;// POST /user&lt;/span&gt;
  &lt;span class="c1"&gt;// Body: username, password&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="cm"&gt;/*  #### Hapi.js ####   */&lt;/span&gt;
  &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
          &lt;span class="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Provided data validation by default
&lt;/h3&gt;

&lt;p&gt;Hapi.js provides you with type validation for input from client with Joi package. When invalid input comes from HTTP Request to certain endpoints, the endpoints throw the error and block to execute handler method at the request level.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Joi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
          &lt;span class="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above example, if username is &lt;code&gt;123234&lt;/code&gt; which is number, that endpoint throw the error and block to execute loginUser method. So it is much safer and easier to find what invalid data comes in.&lt;/p&gt;

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

&lt;p&gt;Hapi.js gives me chances to learn other Node.js Framework and the pursuit of Hapi.js. I feel like the creator of &lt;code&gt;Hapi.js&lt;/code&gt; really understand how developers feel when they work. I don't know much about Hapi.js so there probably are lots of features to comfort developers.&lt;/p&gt;

&lt;p&gt;I am coming back to the next article soon!!&lt;/p&gt;

&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://simpleprogrammer.com/introduction-hapijs/"&gt;https://simpleprogrammer.com/introduction-hapijs/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hueniverse.com/why-you-should-consider-hapi-6163689bd7c2"&gt;https://hueniverse.com/why-you-should-consider-hapi-6163689bd7c2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>hapijs</category>
      <category>api</category>
    </item>
  </channel>
</rss>
