<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Benedict Nkeonye</title>
    <description>The latest articles on Forem by Benedict Nkeonye (@benneee_).</description>
    <link>https://forem.com/benneee_</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%2F135725%2F22f6b49e-1f23-4c19-95d5-f78b4ddc9278.jpg</url>
      <title>Forem: Benedict Nkeonye</title>
      <link>https://forem.com/benneee_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/benneee_"/>
    <language>en</language>
    <item>
      <title>Building TVFlixx</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Sat, 13 Aug 2022 10:49:21 +0000</pubDate>
      <link>https://forem.com/benneee_/building-tvflixx-15oo</link>
      <guid>https://forem.com/benneee_/building-tvflixx-15oo</guid>
      <description>&lt;p&gt;Hiya!&lt;/p&gt;

&lt;p&gt;A little over two years ago, I &lt;a href="https://dev.to/benneee_/learning-vue-js-5bjg"&gt;started my journey&lt;/a&gt; into the world of Vue.js after a long and probably-never-ending stint with Angular. Working with Vue.js has been rewarding and there are more things to uncover even as work continues on the amazing framework and its libraries, e.g Nuxt.js.&lt;/p&gt;

&lt;p&gt;Working with Angular gave me working TypeScript knowledge, but I (have) never tried to build anything with TypeScript outside Angular. I had to do a quick &lt;a href="https://github.com/Benneee/ts-play" rel="noopener noreferrer"&gt;refresh on TypeScript&lt;/a&gt; with a &lt;a href="https://scrimba.com/learn/typescript" rel="noopener noreferrer"&gt;scrimba course&lt;/a&gt; and &lt;a href="https://github.com/Benneee/vue-ts-play" rel="noopener noreferrer"&gt;toe-dipping&lt;/a&gt; into the Vue.js&amp;lt;&amp;gt;TypeScript world with this &lt;a href="https://www.youtube.com/watch?v=JfI5PISLr9w" rel="noopener noreferrer"&gt;amazing YouTube playlist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I am a huge TV shows fan, and I &lt;a href="https://twitter.com/search?q=(series%2C%20OR%20TV%20shows)%20(from%3Abenneee_)&amp;amp;src=typed_query&amp;amp;f=top" rel="noopener noreferrer"&gt;tweet&lt;/a&gt; a lot about my current favorites (follow me 🤩!), but I never thought about building an app to play around with TV shows data until now. &lt;br&gt;
I built &lt;a href="https://github.com/Benneee/moflixx" rel="noopener noreferrer"&gt;Moflixx&lt;/a&gt; with Angular sometime in 2019 but It was based on a Movies API. I wanted to build an application that would help me work with Vue.js (Composition API) and TypeScript and now felt like a great time to play around with some TV shows data.&lt;/p&gt;
&lt;h3&gt;
  
  
  The User Interface
&lt;/h3&gt;

&lt;p&gt;Like &lt;a href="https://github.com/Benneee/moflixx" rel="noopener noreferrer"&gt;Moflixx&lt;/a&gt;, I needed an API to fetch TV shows data from. It took a few days, but I found &lt;a href="https://episodate.com" rel="noopener noreferrer"&gt;Episodate&lt;/a&gt; surprisingly off a series of GitHub search. I explored the data, it wasn't super robust in terms of endpoints available but It had everything I needed for &lt;code&gt;TVFlixx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I needed some inspiration for the UI, but I did not also want to stray too far away from what my datasource website looked like, &lt;a href="//https//episodate.com"&gt;Episodate&lt;/a&gt;'s interface pretty much did it for me, so I borrowed a few UI tips.&lt;/p&gt;

&lt;p&gt;Next, I needed a structure for &lt;code&gt;TVFlixx&lt;/code&gt;. I wrote down a list of components and pages I felt I would need and sketched a few things as well for the components. A regular for me in this type of application is the &lt;code&gt;Favorites&lt;/code&gt; page.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pages&lt;/th&gt;
&lt;th&gt;Components&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;- &lt;code&gt;TVShows&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;Episodes&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;- &lt;code&gt;NotFound&lt;/code&gt; / &lt;code&gt;404&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;Pagination&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;- &lt;code&gt;TVShowDetails&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;Header&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;- &lt;code&gt;Favorites&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;TVShow&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;TVShowList&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;Loading&lt;/code&gt; component&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;Carousel&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;- &lt;code&gt;CarouselItem&lt;/code&gt; component&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the help of a few resources, I built some components I could have easily installed a few packages for.&lt;br&gt;
For the next few paragraphs, I will explain the reasoning behind the choice of some components.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TVShows&lt;/code&gt; page is a simple page that shows a paginated list of TV shows from the API, 20 items are shown on each page depending on the items available from the API.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TVShowDetails&lt;/code&gt; page employs more of the other components.&lt;br&gt;
For instance, I use the &lt;code&gt;Carousel&lt;/code&gt; and &lt;code&gt;CarouselItem&lt;/code&gt; components to show a list of images that comes with each TV show item - this helps any prospective user view the images one at a time or select any image from the preview.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhh5k8p8if8ttabtvrdz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhh5k8p8if8ttabtvrdz.png" alt="Carousel component" width="732" height="1018"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also use the &lt;code&gt;Episodes&lt;/code&gt; component in the &lt;code&gt;TVShowDetails&lt;/code&gt; page, the component takes an &lt;code&gt;episodes&lt;/code&gt; prop which is an &lt;code&gt;array&lt;/code&gt; of all the episodes contained in &lt;code&gt;objects&lt;/code&gt; for a particular TV show. This component filters each item in the array by their season and creates a view that enable users view list of episodes per season by selecting a button showing the season they are interested in.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxseum3vaj1f8pfj8n8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxseum3vaj1f8pfj8n8g.png" alt="Episodes component UI" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TVShow&lt;/code&gt; component needed a few iterations before I could get what I wanted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hd0501swmx25hm1hx4v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hd0501swmx25hm1hx4v.jpg" alt="Sketch" width="800" height="685"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wanted an hover effect to cause the card to flip to the other side to show some details and allow a user "see more details" about the TV show, took a while but I achieved it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Front of card&lt;/th&gt;
&lt;th&gt;Flip side&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v1ki3usdjyluncaa70q.png" alt="Front" width="548" height="834"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F940woyt6gbc3zm2zuwul.png" alt="Flip side" width="548" height="856"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The other components are pretty much self-explanatory.&lt;/p&gt;
&lt;h3&gt;
  
  
  The TypeScript Part
&lt;/h3&gt;

&lt;p&gt;I use the &lt;code&gt;Volar&lt;/code&gt; extension in my VS Code, so I had to enable the &lt;code&gt;Template Interpolation Service&lt;/code&gt; to do some validation and code completion in the template. I also wanted to explore the Composition API more and using the &lt;code&gt;defineComponent&lt;/code&gt; method from &lt;code&gt;vue&lt;/code&gt; was a good decision.&lt;/p&gt;

&lt;p&gt;First, I knew I had to define the structure for the objects I would be using within the app. I created some interfaces to handle the data coming into each page and component and tried really hard to avoid the &lt;code&gt;any&lt;/code&gt; type 😅.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Episodes&lt;/code&gt; component required a special custom type different from the other interfaces I created, because it eventually provided an &lt;code&gt;object of arrays&lt;/code&gt; and the type for the &lt;code&gt;key&lt;/code&gt; for the items in the object weren't exactly known or constant before runtime as they were the values of the &lt;code&gt;season&lt;/code&gt; field for the episodes. &lt;br&gt;
This &lt;a href="https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures" rel="noopener noreferrer"&gt;extract&lt;/a&gt; from the TypeScript docs came in handy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Episode from "./Episode"

interface SeasonEpisodes { 
    [index: string]: Episode[]
}

export default SeasonEpisodes;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also needed to handle issues around passing props to the components and ensuring the right type was enforced for the objects using type assertion with &lt;code&gt;PropType&lt;/code&gt; imported from &lt;code&gt;vue&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;I use the composition API extensively at work, but using it with TypeScript encourages a bit more sanity within the codebase and data flow across components.&lt;br&gt;
I will probably do some tweaks in the application (especially the UI) in the future but I really just wanted to focus on how I could work with the composition API and TypeScript.&lt;/p&gt;

&lt;p&gt;I wanted to share my thoughts around working with TypeScript and Vue.js, this article mostly captures the parts I thought were worth talking about. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Benneee/tvflixx" rel="noopener noreferrer"&gt;The Repository on GitHub&lt;/a&gt; - star the repo if you enjoyed this!&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures" rel="noopener noreferrer"&gt;TypeScript docs excerpt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://episodate.com" rel="noopener noreferrer"&gt;The UI inspiration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://episodate.com/api" rel="noopener noreferrer"&gt;API resource&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=6-JEiEfkluc" rel="noopener noreferrer"&gt;The Carousel component&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/vuejs-vue-pagination-component" rel="noopener noreferrer"&gt;The Pagination component&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>typescript</category>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Learning Vue.js</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Sat, 16 May 2020 00:54:41 +0000</pubDate>
      <link>https://forem.com/benneee_/learning-vue-js-5bjg</link>
      <guid>https://forem.com/benneee_/learning-vue-js-5bjg</guid>
      <description>&lt;p&gt;Hello there!&lt;/p&gt;

&lt;p&gt;My first introduction to JavaScript frameworks and libraries was sometime in October 2018 and the framework was Angular. Almost two years down the line, I have relatively tried nothing else, Apart from some contributions I made to &lt;a href="https://github.com/MichaelGee/newsrack"&gt;a friend's React project&lt;/a&gt; very recently, I only have a &lt;a href="https://github.com/Benneee/CartApp"&gt;ToDo application&lt;/a&gt; written in React and that's all, however, &lt;a href="https://github.com/Benneee/"&gt;most of my projects&lt;/a&gt;, both work, and side projects are/were created using Angular.&lt;/p&gt;

&lt;p&gt;I recently built the back-end for my personal website using Node.js and Express, this comes off the heels of taking some months to dive into another JavaScript framework and the Back-end as I've been a Front-end developer all my dev-life. I wanted to understand the MEAN Stack, so Node.js made sense at the time. I wrote about that journey &lt;a href="https://dev.to/benneee_/learning-node-js-express-1-3ckj"&gt;here&lt;/a&gt;, it also involved an &lt;a href="https://github.com/mdn/express-locallibrary-tutorial/pull/83"&gt;open-source contribution&lt;/a&gt; to MDN's Tutorial on Node.js and Express. 🙌 &lt;/p&gt;

&lt;p&gt;I recently started learning Vue. I am currently using Vuemastery and I have so far enjoyed the simplicity of the beginner track course and the method they have adopted. As some of you would expect, I went into the course looking for similarities and differences between my comfort zone, Angular, and Vue.js, this is partly due to statements I have heard and read about Vue.js in the past. One of them is &lt;em&gt;Vue.js takes the best parts of Angular and React&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I am still very much a beginner in Vue.js, I have not even used the Vue CLI as I am thoroughly enjoying the script tag for now, but I have so far been able to draw up a few points of similarities or differences between Angular and Vue.js. &lt;/p&gt;

&lt;h4&gt;
  
  
  Disclaimer: I still have not used the Vue CLI, the next set of points are from my experience using the Vue.js starter script tag.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I immediately understood the Vue Instance as the heart of the Vue application, this was easily comparable to the app-component in an Angular application. My views on this particular point might change when I have to create a Vue.js project with its CLI.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We have &lt;a href="https://angular.io/guide/structural-directives"&gt;structural directives&lt;/a&gt; in Angular, three of the common ones are NgIf, NgFor, and NgSwitch. Vue.js has v-if, v-for, and v-else, e.t.c. I like how v-show is present in Vue.js, we had NgShow in AngularJS, but NgIf in Angular2++ has us covered to a good extent, even though it has its quirks (like using the NgIf directive when working with ChartJS in Angular), you are better off using the 'hidden' attribute instead.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Part of the things I had to pick up early in Angular was communication between components and events played a major part in this aspect. I am yet to find the equivalent of Angular's Input and Output in Vue.js, however, in the case of events, it is pretty straightforward to understand it the way I understood events and property binding in Angular.
I would say 'v-on' or '@' for event binding in Vue.js, round brackets, '()' for event binding in Angular.
I would also say 'v-bind' or ':' for property binding in Vue.js, square brackets, '[]', for property binding in Angular.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;For transmission of events in Angular, we use the EventEmitter and its emit method, while in Vue.js, there is the component's $emit method. I also like how flexible it is to use the $emit method, especially how you can pass arguments to it in the process, two arguments - the event and perhaps, if needed, an ID. In Angular, we pass the $event as a parameter.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;I have also seen the presence of props in Vue.js as I created my first Vue.js component last night ☺️, this is a similarity with React, if it is used in the same way, that's still something I will have to discover as I continue the journey.&lt;/p&gt;

&lt;p&gt;I hope to turn this into a series and I am looking forward to more similarities or differences as these comparisons help me understand Vue.js even better, with my background as an Angular developer playing a huge role.&lt;/p&gt;

&lt;p&gt;Kindly drop comments if I missed out anything, no spoilers please, thank you.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>angular</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Creating A Show-or-Hide-Password Feature For Angular Forms</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Sat, 15 Feb 2020 03:22:56 +0000</pubDate>
      <link>https://forem.com/benneee_/creating-a-show-or-hide-password-feature-for-angular-forms-4fdk</link>
      <guid>https://forem.com/benneee_/creating-a-show-or-hide-password-feature-for-angular-forms-4fdk</guid>
      <description>&lt;p&gt;Hello there!&lt;/p&gt;

&lt;p&gt;A few days ago, I had to help our users on one of our products get their password right on the first try and some people, as I have observed, do not like not being able to see what they are typing, hence the need for this feature.&lt;/p&gt;

&lt;p&gt;In this write-up, I hope to show you how to create a show or hide feature in your password input in Angular forms.&lt;/p&gt;

&lt;h4&gt;
  
  
  Our arsenal for the adventure
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The wonderful Angular Reactive forms&lt;/li&gt;
&lt;li&gt;The ngClass directive&lt;/li&gt;
&lt;li&gt;A bit of Bootstrap's beauty&lt;/li&gt;
&lt;li&gt;Awesome Fontawesome icons&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, let's get serious...&lt;/p&gt;

&lt;p&gt;First, we create a new angular project. I have angular version 8 installed globally in my machine, but you can still follow along.&lt;/p&gt;

&lt;pre&gt;
                           ng new show-hide-password
&lt;/pre&gt;

&lt;p&gt;You'd get a few prompts about routing, stylesheets and git initialization, you can do as you please.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installation of packages
&lt;/h4&gt;

&lt;p&gt;After the creation process was completed, I opened the project in my text editor to begin the necessary installations, starting with Bootstrap using npm. This &lt;a href="https://github.com/Benneee/show-hide-password/tree/installations" rel="noopener noreferrer"&gt;repository branch&lt;/a&gt; has the necessary information for the Bootstrap version installed. I installed Fontawesome as well since we will be using the icons available. The command below would suffice.&lt;/p&gt;

&lt;pre&gt;
                            npm i bootstrap font-awesome
&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;Note: please check the project's &lt;a href="https://github.com/Benneee/show-hide-password/blob/master/package.json" rel="noopener noreferrer"&gt;package.json&lt;/a&gt; for any other dependency installed. These include jquery, popper and angular-font-awesome, now, let's go back to the article.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Creating The Form
&lt;/h4&gt;

&lt;p&gt;I created a new component called 'sample-form', this component is to hold our form.&lt;br&gt;
I replaced the content of the app.component.html file with a navbar markup and the selector for the sample-form component.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Our form looks like this now:&lt;/li&gt;
&lt;/ul&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%2Fv9jl0ehcoh19mrej4sdb.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%2Fv9jl0ehcoh19mrej4sdb.png" alt="Sample Form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, It is a reactive form and I'll share the code as well.&lt;br&gt;
The component:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The template:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here's the &lt;a href="https://github.com/Benneee/show-hide-password/tree/ft-create-form" rel="noopener noreferrer"&gt;repository branch&lt;/a&gt; concerned with this section for your perusal.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Fun Part
&lt;/h4&gt;

&lt;p&gt;So far, we have created the form and given it some basic styling, now we need to bring in the fontawesome icons and introduce the logic to show or hide the password. &lt;br&gt;
Firstly, we have to edit our markup to accommodate the icons. Bootstrap has a very useful class called the &lt;a href="https://getbootstrap.com/docs/4.1/components/input-group/" rel="noopener noreferrer"&gt;input-group&lt;/a&gt; in the forms category, within the input group class, we have the 'input-group-append' and 'input-group-prepend' classes. &lt;br&gt;
These classes position the icons for us just on the ends of the input, neatly as well. We use 'prepend' for our email input and 'append' for the password inputs. See the extracts of the markup below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The form looks like this now:
&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%2Fbc0baye0vrwgvldbj5ew.png" alt="Sample form with icons"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the &lt;a href="https://github.com/Benneee/show-hide-password/tree/ft-add-icons" rel="noopener noreferrer"&gt;repository branch&lt;/a&gt; for this section for your perusal.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Serious Fun Part, seriously :)
&lt;/h4&gt;

&lt;p&gt;We are eighty percent done with our form, now we just need to add that logic to show or hide the password. We employ the ngClass directive, a one-liner from the official &lt;a href="https://angular.io/api/common/NgClass" rel="noopener noreferrer"&gt;angular docs&lt;/a&gt; says 'NgClass adds and removes CSS classes on an HTML element'. Now, that's cool but there's something even way cooler, we can use NgClass with conditionals, here's a small explanation with code.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, because of this amazing ngClass property, we can create a condition for when we want to show our password or hide it. The most popular trick about 'show or hide password' is to convert the form input type from 'password' to 'text' and that is exactly what we do here. We do have to declare the property 'fieldTextType' in our component first.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Next, we bring in ngClass for the action part.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the component, we have a toggleFieldType method doing the switch.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Here is the &lt;a href="https://github.com/Benneee/show-hide-password/tree/ft-logic" rel="noopener noreferrer"&gt;repository branch&lt;/a&gt; concerned with this section.&lt;/p&gt;

&lt;p&gt;Our form finally works like this:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/22deGrKOXSM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;In this article, we have seen how to use the ngClass directive to create a 'show-or-hide' feature for our password input in angular forms.&lt;br&gt;
The project is hosted &lt;a href="https://show-hide-password.now.sh" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
Find the full code in the repo linked below, the master branch is updated.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Benneee" rel="noopener noreferrer"&gt;
        Benneee
      &lt;/a&gt; / &lt;a href="https://github.com/Benneee/show-hide-password" rel="noopener noreferrer"&gt;
        show-hide-password
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      The repository for my dev.to post (https://bit.ly/2SGChq0) on show/hide password feature using features in Angular.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;ShowHidePassword&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;This is the repository for my article on creating a show or hide password feature up on &lt;a href="https://dev.to/benneee_/creating-a-show-or-hide-password-feature-for-angular-forms-4fdk" rel="nofollow"&gt;dev.to&lt;/a&gt;.
&lt;a rel="noopener noreferrer" href="https://github.com/Benneee/show-hide-passwordshowhidepassword.gif"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBenneee%2Fshow-hide-passwordshowhidepassword.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The article explains how we use ngClass, angular forms, bootstrap 4 and fontawesome icons to create such a helpful feature, enjoy the post! I hope you find it useful someday.&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Benneee/show-hide-password" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Thank you for reading, I hope you find this useful someday.&lt;br&gt;
Kindly drop your comments or feedback, I'll be grateful.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>angularforms</category>
      <category>dev</category>
      <category>passwords</category>
      <category>angular</category>
    </item>
    <item>
      <title>Learning Node.js &amp; Express (4)</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Wed, 20 Nov 2019 22:30:42 +0000</pubDate>
      <link>https://forem.com/benneee_/learning-node-js-express-4-j6o</link>
      <guid>https://forem.com/benneee_/learning-node-js-express-4-j6o</guid>
      <description>&lt;p&gt;Hiya! It is wonderful to be back with you again today.&lt;/p&gt;

&lt;p&gt;In our previous meeting, I talked about hooking &lt;a href="https://github.com/Benneee/Learning-Node-JS/tree/master/local-library" rel="noopener noreferrer"&gt;Local Library&lt;/a&gt; up with a MongoDB database, I mentioned a few tips that helped me avoid the pitfalls during the configuration of the database. I also talked about models, routes and controllers and explained their relative duties as far as our project is concerned.&lt;/p&gt;

&lt;p&gt;A quick reminder that this series is based on my learnings from &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today, I will be talking to us about "Displaying the Local Library Data", there will be two main talking points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Asynchronous Flow Using the 'Async' Module&lt;/li&gt;
&lt;li&gt;Templates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get to it then!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous Flow Using the 'Async' Module&lt;/strong&gt;&lt;br&gt;
Due to the asynchronous nature of our requests for data from the database, we need to be able to control the flow of the data. Node.js provides the 'async' module for this reason. Three important methods of the async module are 'async.parallel', 'async.series' and 'async.waterfall'.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://caolan.github.io/async/v3/docs.html#parallel" rel="noopener noreferrer"&gt;async.parallel&lt;/a&gt; is used when requests must be made in parallel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://caolan.github.io/async/v3/docs.html#series" rel="noopener noreferrer"&gt;async.series&lt;/a&gt; is used to handle requests that must be made in series and each subsequent request is not dependent on the previous request's result. So, in a way, this does work like async.parallel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://caolan.github.io/async/v3/docs.html#waterfall" rel="noopener noreferrer"&gt;async.waterfall&lt;/a&gt; handles requests that must be made in series and where the next request is dependent on the result of the current request. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Templates&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;A template is a text file defining the structure or layout of an output file, with placeholders used to represent where data will be inserted when the template is rendered.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It is worthy to note that different template languages use different approaches for defining the layout and marking placeholders for data in the template.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some use HTML to define the layout&lt;/li&gt;
&lt;li&gt;Some use markup format that can be compiled to HTML (e.g pug)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pug is a clean and white-space sensitive template language. It reminded me a bit of Python at first glance. Pug has some attributes that will help one create amazing pages, the drawback, however, is that the error messages generated are not the most helpful, plus its white-space sensitivity is very important to remember when creating markup with it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some features of Pug&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Element attributes are defined in parentheses after their associated element. Inside the parentheses, the attributes are defined in the comma-separated list of pairs of attribute name and attribute values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a tag is followed by the equals sign, the following text is treated as a JavaScript expression (read &lt;em&gt;variable&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can also concatenate variables with plain text in the template. The plain text has to be in quotes.&lt;br&gt;
e.g p='Evaluated expression: ' + &lt;em&gt;title&lt;/em&gt;&lt;br&gt;
&lt;em&gt;title&lt;/em&gt; above is a variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can also extend templates. In a large site where you have different pages, you are bound to have, at least, the starter template of any HTML file  - the head section - in all the pages. A base template can be defined to hold the boilerplate markup and on the other pages, the &lt;em&gt;extends&lt;/em&gt; keyword is used to reference this base template. &lt;br&gt;
See &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Displaying_data/Template_primer" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more details on templates.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now, let us see the improvements the async module and templates have brought to the Local Library project.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first template created was the layout.pug file, this file represents our base template for the Local Library project. The design for the local library user interface is such that it has a sidebar for navigation and because this is expected to be seen in all the different pages, we place the markup in layout.pug. We use Bootstrap 3.3.7 for styling in this project&lt;br&gt;
For cognisance, the pages that will be seen in the Local Library project include &lt;br&gt;
&lt;em&gt;Book&lt;/em&gt;, &lt;em&gt;Author&lt;/em&gt;, &lt;em&gt;Book instance (copies of books)&lt;/em&gt;, &lt;em&gt;Genre&lt;/em&gt;.&lt;br&gt;
On the homepage of the project, we show a list of all records and the count for each of them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We update the bookController.js file to return the count of each of our records using the countDocument method provided by mongoose. We use the async.parallel method to handle the request to get the data from our database. The models for the other resources are first imported into the bookController.js file so that their data can be accessed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55k4k7q2ylopjc4baf5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F55k4k7q2ylopjc4baf5v.png" alt="Snapshot of how we used async.parallel" width="545" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We update the view (index.pug) with dynamic content generated after the results are received from the controller. The snapshot below shows this process.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjts8nu1tuq9kdtqa4aqf.png" alt="Updating the view with dynamic content" width="587" height="250"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what our Local Library looks like for now:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg75dg67dtozxd4qn9v22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg75dg67dtozxd4qn9v22.png" alt="The Local Library Homepage" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;P.S Content for the other pages will be generated later in subsequent articles.&lt;/p&gt;

&lt;p&gt;Thank you for joining me today, I do hope you learnt a thing or two.&lt;/p&gt;

&lt;p&gt;Happy Coding!!&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>mongodb</category>
      <category>backend</category>
    </item>
    <item>
      <title>Learning Node.js &amp; Express (3)</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Tue, 19 Nov 2019 22:17:24 +0000</pubDate>
      <link>https://forem.com/benneee_/learning-node-js-express-3-30j9</link>
      <guid>https://forem.com/benneee_/learning-node-js-express-3-30j9</guid>
      <description>&lt;p&gt;Hiya everyone!&lt;/p&gt;

&lt;p&gt;A quick recap of what was discussed in the previous part of this series:&lt;br&gt;
I talked about View Engines and Database. I also shared links to the MDN articles that will help you make decisions when selecting a View Engine or Database. I also mentioned ORMs and ODMs which are one of the two ways we can communicate with the preferred database, the other way is using the database native query language.&lt;/p&gt;

&lt;p&gt;Today, I want to talk about Models ==&amp;gt; Controllers ==&amp;gt; Routes and how I created them for the local library project following the Mozilla Development Network &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs" rel="noopener noreferrer"&gt;Node.js &amp;amp; Express Tutorials&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before we dive in, I had to set up the database. The database adopted for the Local Library project is MongoDB, hence, we use the Mongoose ORM to communicate with the Database; creating, listing, updating and deleting files are done using the Mongoose methods. As I mentioned in the previous part of this write-up, using an ORM such as Mongoose helps us to continue thinking in terms of Javascript objects and avoid database semantics.&lt;/p&gt;

&lt;p&gt;I already have an account on &lt;a href="//cloud.mongodb.com"&gt;MongoDB cloud facility&lt;/a&gt;, all I needed to do was to create a new database and cluster. The process is well explained in the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose#Setting_up_the_MongoDB_database" rel="noopener noreferrer"&gt;Mongoose section&lt;/a&gt; of the MDN tutorial. &lt;br&gt;
However, here are some tips that would save you some time and headache:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the "Connect to Cluster" section, you need to add an IP address that will allow you connect to the database from anywhere. The address given in the tutorial, '0.0.0.0/0', will not work as at the time of writing this post, what you want to type in there is '127.0.0.0.1'. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you copy the connection string according to the last part of the instructions for setting up the MongoDB database, change 'test' in the connection string to 'local_library' as this is what you titled your database and you'd most likely be looking for your data after populating the database in the wrong place if you do not make this change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After setting up the cluster and database completely, you now want to go back to edit the IP address you entered, the page will be opened up on another tab and as at that time, you'll be able to type in '0.0.0.0/0'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mongoose is then installed and the script to connect to the database is seen in &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose#Connecting_to_MongoDB" rel="noopener noreferrer"&gt;this section&lt;/a&gt; of the MDN tutorial.&lt;br&gt;
Another serious tip:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Mongoose.connect returns a promise, please remember to handle this by calling the .then and .catch or however you choose to handle the promise. The code linked above did not include this part.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You also want to add another option inside the connect object other than useNewUrlParser, useUnifiedTopology, this should also be given a value of true just like the useNewUrlParser, see the snapshot below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflirjrwwbqfr9bbguece.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflirjrwwbqfr9bbguece.png" alt="Snapshot of the MongoDB Connection Section" width="563" height="165"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, we can now talk about Models ==&amp;gt; Routes ==&amp;gt; Controllers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt;&lt;br&gt;
Models help us define a structure for our data. We can however not create models if we have not designed a relationship between the different parts of our application. For our models, Mongoose provides the 'Schema' interface. This interface helps us define the models we need for Local Library. &lt;br&gt;
When designing models, it makes sense to have separate models for every object - a group of related information, e.g select-list options&lt;br&gt;
The Schema describes the value type expected for a particular item.&lt;br&gt;
examples of the models for Local Library includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;author.js&lt;/li&gt;
&lt;li&gt;book.js
Mongoose also provides the 'virtual' interface. A virtual is created in a model and it can be used to get the named URL required to get an instance of a model. We can use this property within the template when we need a link to a particular author, for instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Controllers&lt;/strong&gt;&lt;br&gt;
Controllers are basically functions that separate out the code to route the request from the code that processes the request. Mindboggling, yes? worry not, I will explain.&lt;br&gt;
Basically, what the controller does is that it provides the data required when the route linked to the model property it is attached to. For instance, under the authors model, we have a property in our controller linked to this model called the author_list, this controller property displays a list of authors. Eventually, the route linked to this author_list calls the controller which in turn calls the model and a call is made to the database which provides the list of authors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Routes&lt;/strong&gt;&lt;br&gt;
A route is a section of express code that associates an HTTP verb (GET, POST, PUT, DELETE), a URL path/pattern and a function (controller) that is called to handle the path/pattern.&lt;br&gt;
Routes can be considered to be the URL handling code. The Express Router is required and used within the module. The controller files are also required so that the different parts for each model can be routed to if they have some data to be displayed.&lt;br&gt;
Basically, the route calls the controller, the controller calls the model and the model calls the database, once there is a response, the data is sent back all the way to the controller which provides an HTTP response and/or provides the content for the template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, I talked about setting up the database and clusters needed for the Local Library project, I also talked about Models, Controllers and Routes and how they work together to present data to the View or as an HTTP Response.&lt;br&gt;
In the next write-up, I will be talking about Displaying the Library Data to the view and other related topics.&lt;/p&gt;

&lt;p&gt;P.S. Some data was used to populate the DB using a populatedb.js file which contained scripts pushing the data to our MongoDB database. Inside the populatedb.js file, you also want to handle the promise that mongoose.connect method returns as it was not also handled in the script.&lt;/p&gt;

&lt;p&gt;Follow my progress on &lt;a href="https://github.com/Benneee/Learning-Node-JS" rel="noopener noreferrer"&gt;Local Library&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you next time!&lt;/p&gt;

&lt;p&gt;Happy Coding!!&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>mongodb</category>
      <category>backend</category>
    </item>
    <item>
      <title>Learning Node.js &amp; Express (2)</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Mon, 18 Nov 2019 20:40:27 +0000</pubDate>
      <link>https://forem.com/benneee_/learning-node-js-express-2-5f3i</link>
      <guid>https://forem.com/benneee_/learning-node-js-express-2-5f3i</guid>
      <description>&lt;p&gt;Hello once again!&lt;/p&gt;

&lt;p&gt;Yesterday, I &lt;a href="https://dev.to/benneee_/learning-node-js-express-1-3ckj"&gt;wrote&lt;/a&gt; briefly about how I have started learning Node.js and Express. I mentioned I would be sticking with the tutorial on &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction" rel="noopener noreferrer"&gt;Mozilla Development Network for Node.js and Express&lt;/a&gt;. I also talked about other supporting materials such as &lt;a href="https://www.amazon.com/Beginning-Node-js-Basarat-Syed/dp/1484201884/ref=sr_1_1?keywords=BEGINNING+NODEJS&amp;amp;qid=1574029505&amp;amp;s=digital-text&amp;amp;sr=8-1" rel="noopener noreferrer"&gt;Beginning Node.js&lt;/a&gt; and &lt;a href="https://www.amazon.com/Learn-NodeJS-Day-Complete-Examples-ebook/dp/B01N7A4NFT" rel="noopener noreferrer"&gt;Learn NodeJS in One Day&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today, I want to run through my progress so far and share a few things I have come to understand so far. The first thing I created after going through the theoretical parts of Node.js from the 'Learn Node.js in One Day' book was this &lt;a href="https://github.com/Benneee/Learning-Node-JS/blob/master/index.js" rel="noopener noreferrer"&gt;simple server&lt;/a&gt;, all it did was print "Hello World" on the screen when you navigate to port 8000 while the code is running in the terminal. This made me smile.&lt;/p&gt;

&lt;p&gt;I dove deeper into the MDN tutorials in the next few days, then I got introduced to the minimalist and unopinionated Node.js web framework called Express. One of the things I like about Express is the Express Generator, simply because of the ease to generate a project by using &lt;em&gt;express name-of-app/project&lt;/em&gt;. On running this command, the following will be generated: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoz5xmjb5yg2l7l7zwuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoz5xmjb5yg2l7l7zwuz.png" alt="Snapshot of files &amp;amp; directories generated" width="680" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will talk about these files in a later article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View Engines&lt;/strong&gt;&lt;br&gt;
The MDN tutorial's first project endeavour is to build a local library website, now, you would expect a website to have actual pages we can see stuff like 'books', right? Node.js does provide us with view options made possible by something called 'Template Engines'. These &lt;a href="https://github.com/expressjs/express/wiki#template-engines" rel="noopener noreferrer"&gt;Template Engines&lt;/a&gt; help us to present data on the client-side. Ordinarily, the default template engine provided if you run &lt;em&gt;express hello-world&lt;/em&gt; would be the engine called &lt;a href="https://pugjs.org/api/getting-started.html" rel="noopener noreferrer"&gt;Pug (formerly Jade)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;MDN does a good job of explaining consideration points before selecting a template, some of them include: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Time to productivity&lt;/li&gt;
&lt;li&gt;Popularity and activity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the write-up &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/skeleton_website#What_view_engine_should_I_use" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;br&gt;
When building APIs, you will most likely want to save data somewhere, persist whatever is created or edited on the client, this is where the database comes in. Node.js works with various types of database, SQL or NoSQL and Express works with the databases Node.js supports as it does not have any specifics when it comes to Databases. &lt;br&gt;
MDN describes how you can communicate with your preferred database in two ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the database's native query language&lt;/li&gt;
&lt;li&gt;Using an Object Data Model or Object Relational Model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good example of the second option is Mongoose, the ORM/ODM used to communicate with a MongoDB database. Choosing an ORM like Mongoose is advantageous because we can avoid the use of database semantics and continue thinking in terms of JavaScript objects. These &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose#What_ORMODM_should_I_use" rel="noopener noreferrer"&gt;points from MDN&lt;/a&gt; can help you make a decision when selecting an ORM or ODM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, I talked about the Express Generator, View engines and Database. In the next set of articles, I will talk about the Local Library project and my progress in it so far. As always, the code for this journey &lt;a href="https://github.com/Benneee/Learning-Node-JS" rel="noopener noreferrer"&gt;lives here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for sticking with me to this point. &lt;br&gt;
Happy Building!&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>mongodb</category>
      <category>backend</category>
    </item>
    <item>
      <title>Learning Node.js &amp; Express (1)</title>
      <dc:creator>Benedict Nkeonye</dc:creator>
      <pubDate>Sun, 17 Nov 2019 22:55:25 +0000</pubDate>
      <link>https://forem.com/benneee_/learning-node-js-express-1-3ckj</link>
      <guid>https://forem.com/benneee_/learning-node-js-express-1-3ckj</guid>
      <description>&lt;p&gt;I have been a &lt;a href="https://medium.com/@benedictiknkeonye/the-latest-codenewbie-1facf1f33915?source=---------2------------------"&gt;front-end developer since my break&lt;/a&gt; into the technology industry, a little over a year now. My first programming language was actually Python, but that relationship was a bit too short and an internship opportunity came for me which entailed learning JavaScript and subsequently, Angular, I immediately grabbed it.&lt;/p&gt;

&lt;p&gt;I, however, have a goal to understand the MEAN Stack before the end of 2019. This meant I had to learn Node.js, Express and MongoDB (not in its entirety since there's mongoose).&lt;/p&gt;

&lt;p&gt;A friend told me about the MongoDB University courses, I thought it would be a great place to start since it was learning directly from the source. I had to take the basic level thrice because I failed once and could not meet up the timeline for the tests in the first attempt. I was third time lucky. This happened in September.&lt;/p&gt;

&lt;p&gt;In the first week of October, I decided it was time to start learning Node.js. I decided to scour UDEMY and other similar places for courses on Node.js but they all looked really long for the moment and I really wanted to read this time, I was fed up with the video tutorials. &lt;/p&gt;

&lt;p&gt;I settled for two books; &lt;a href="https://www.amazon.com/Beginning-Node-js-Basarat-Syed/dp/1484201884/ref=sr_1_1?keywords=BEGINNING+NODEJS&amp;amp;qid=1574029505&amp;amp;s=digital-text&amp;amp;sr=8-1"&gt;Beginning Node.js&lt;/a&gt; and &lt;a href="https://www.amazon.com/Learn-NodeJS-Day-Complete-Examples-ebook/dp/B01N7A4NFT"&gt;Learn NodeJS in One Day&lt;/a&gt;. I consulted a friend who recommended MDN's Node.js &amp;amp; Express Tutorial because he used it.&lt;/p&gt;

&lt;p&gt;I created a &lt;a href="https://github.com/Benneee/Learning-Node-JS"&gt;GitHub repository&lt;/a&gt; to track my progress and store all the code that would be generated during the next few months. I read on transit to and from the office, so I quickly wrapped up the #TransitRead that spilt into October from September just so that I could begin &lt;a href="https://www.amazon.com/Learn-NodeJS-Day-Complete-Examples-ebook/dp/B01N7A4NFT"&gt;Learn NodeJS in One Day&lt;/a&gt;, of course, I couldn't finish the book in one day, heck!, I'm still reading it.&lt;/p&gt;

&lt;p&gt;So far, I have created my first server, writing and rewriting and then understanding what was done in the book, and pushed the code to GitHub. I have read about how Node.js ensures a non-blocking process in its operations and the suitable applications one can adopt a Node.js back-end. Following the MDN tutorial, I've been introduced to Express, a minimalist unopinionated web framework for Node.js and the Express App Generator, a wonderful tool, along with a host of middleware and libraries, if you will.&lt;/p&gt;

&lt;p&gt;I am currently more into the MDN tutorial because of the insight it provides and the things I get to build, although, I really want to understand Node.js in itself before diving into any of its frameworks, fortunately, and unfortunately, MDN dives into Express before I knew what was happening. I did find a Node.js course on UDEMY that dives deep into Node.js before moving on to Express and other frameworks, I'll probably take that after I am done with MDN. For now, it's the book and MDN.&lt;/p&gt;

&lt;p&gt;As I continue this journey, I want to document my experience here, I might mostly talk about my understanding - so more theory and less code. I have learnt quite a lot already, I will write a second part to this article tomorrow to talk about all I have learnt this weekend.&lt;/p&gt;

&lt;p&gt;I'm so excited for what lies ahead!&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>serverside</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
