<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eniola Lucas Fakeye on Medium]]></title>
        <description><![CDATA[Stories by Eniola Lucas Fakeye on Medium]]></description>
        <link>https://medium.com/@enirate?source=rss-2aae6dcffac4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZxPuf-c_WkAHYA2q3fIhDw.jpeg</url>
            <title>Stories by Eniola Lucas Fakeye on Medium</title>
            <link>https://medium.com/@enirate?source=rss-2aae6dcffac4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:59:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@enirate/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How To A Build Real-time React App With Server-Sent Events]]></title>
            <link>https://medium.com/geekculture/how-to-a-build-real-time-react-app-with-server-sent-events-9fbb83374f90?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fbb83374f90</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 18:48:00 GMT</pubDate>
            <atom:updated>2021-06-03T18:45:26.253Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_qd87ohCSg9YWJW-aDh-w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@vmxhu?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Szabo Viktor</a> on <a href="https://unsplash.com/s/photos/real-time?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>The ability to update content in real-time can make the difference between a good and bad user experience. Imagine having to reload your browser to see if the person you are chatting with has sent a new message.</p><p>Some of the ways to achieve real-time content update on the web are long-polling, web sockets and server-side events.</p><p>With long-polling an HTTP request is made to the server at a predefined interval. In server-side events, the browser’s event source API is used to open a channel of communication between the client and the server for updates to flow from the server to the client. The web socket protocol opens a two-way communication channel between the client and the server to allow updates to move in both ways.</p><p>The purpose of this article is to teach you how to leverage the browser EventSource API to build a real-time React application, its limitation and use cases. On that basis, this article shall be divided into three parts.</p><h3>1. The Anatomy Of Server-Sent Events</h3><p>Server-sent events are updates sent in the form of DOM events from the server to the browser. The browser uses the EventSource interface to establish a connection capable of receiving these types of event from the server. An event handler can then registered to handle the incoming event. These can be achieved in a couple of lines of code, depending on is to be done with the received event. Let&#39;s say we want to log the event on the console, it can be done in two lines of code:</p><pre>const source = new EventSource(URL)<br>source.onmessage = e =&gt; console.log(e.data)</pre><ol><li>Create an EventSource instance and specify the event endpoint</li><li>Register an event handler to handle incoming events</li></ol><p>Yes, it can be that simple.</p><h3>1.1 Pros</h3><p>Setting up a web application to receive server-side events is really easy, as seen in the example above. There’s no need for learning how to use or installing a new library because the EventSource interface is a browser API.</p><p>Also, server-side events is <a href="https://caniuse.com/eventsource">supported by majority of browsers</a>.</p><p>While the scope of the article revolves around the frontend, it is worth mentioning that setting up a server to send server-side events to the client is relatively easy compared to web sockets. This is because all you need to do is send an HTTP response with a Content-Type value of text/event-stream; thereby making it language-agnostic and third-party-library-free.</p><h3>1.2 Cons and Comparison With WebSocket</h3><p>With server-sent events only the server can send updates to the client, the client cannot send updates to the server through the same channel i.e the channel of communication is unidirectional.WebSockets, on the other hand, allows full-duplex communication between the server and the client; that is, updates can be sent in both direction in the same connection.</p><p>While the web socket protocol support binary data types, server-sent events only support texts.</p><h3>Applications Of Sever-Sent Events.</h3><p>Server-Side Events are a perfect fit for almost all scenarios in which the server the major or only player responsible for providing updates. Take a stock price app for an example, the price of the stock isn’t updated by user input but it’s calculated by an algorithm and the server can thus update the client when there is a change in price. Other examples of the applications of Server-Side Events include but not limited to:</p><ol><li>A real-time news or information application.</li><li>An application to display the status of an ongoing process.</li></ol><h3>A Real-Time React Application Built With The EventSource API.</h3><h3>3.1 About The Application</h3><p>We shall be building an application that displays the real-time stock prices of selected companies. The prices are not real they are random numbers generated on the server. We shall also create a simple express server from which the react app can get stock prices.</p><h3>3.2 The React Application</h3><p>The react application is quite simple, it’s a single-component [create react app boilerplate](<a href="https://create-react-app.dev/docs/getting-started/">https://create-react-app.dev/docs/getting-started/</a>) that does not utilize any external library. Below is the code of the single-component i.e App.js</p><pre>/*App.js*/</pre><pre>import React, { useState, useEffect } from &quot;react&quot;;<br>import &quot;./App.css&quot;;</pre><pre>const BaseURL = &quot;&lt;http://localhost:8000&gt;&quot;;</pre><pre>function App() {<br>  const [status, setStatus] = useState(&quot;idle&quot;);<br>  const [stockPrices, setStockPrices] = useState([]);</pre><pre>  const formatPrice = (price) =&gt; {<br>    return new Intl.NumberFormat(&quot;us-EN&quot;, {<br>      style: &quot;currency&quot;,<br>      currency: &quot;USD&quot;,<br>      currencyDisplay: &quot;narrowSymbol&quot;,<br>    }).format(price);<br>  };</pre><pre>  const fetchStockPrice = () =&gt; {<br>    setStatus(&quot;idle&quot;);<br>    fetch(`${BaseURL}/stocks`, { method: &quot;GET&quot; })<br>      .then((res) =&gt; (res.status === 200 ? res.json() : setStatus(&quot;rejected&quot;)))<br>      .then((result) =&gt; setStockPrices(result.data))<br>      .catch((err) =&gt; setStatus(&quot;rejected&quot;));<br>  };</pre><pre>  const updateStockPrices = (data) =&gt; {<br>    const parsedData = JSON.parse(data);<br>    setStockPrices((stockPrices) =&gt;<br>      [...stockPrices].map((stock) =&gt; {<br>        if (stock.id === parsedData.id) {<br>          return parsedData;<br>        }<br>        return stock;<br>      })<br>    );<br>  };</pre><pre>  useEffect(() =&gt; {<br>    fetchStockPrice();<br>    const eventSource = new EventSource(`${BaseURL}/realtime-price`);<br>    eventSource.onmessage = (e) =&gt; updateStockPrices(e.data);<br>    return () =&gt; {<br>      eventSource.close();<br>    };<br>  }, []);</pre><pre>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;table&gt;<br>        &lt;caption&gt;Stock Prices&lt;/caption&gt;<br>        &lt;thead&gt;<br>          &lt;tr&gt;<br>            &lt;th&gt;S/N&lt;/th&gt;<br>            &lt;th&gt;Ticker Symbol&lt;/th&gt;<br>            &lt;th&gt;Real Time Price&lt;/th&gt;<br>          &lt;/tr&gt;<br>        &lt;/thead&gt;<br>        &lt;tbody&gt;<br>          {stockPrices.map(({ id, ticker, price }, index) =&gt; (<br>            &lt;tr key={id}&gt;<br>              &lt;td&gt;{index + 1}&lt;/td&gt;<br>              &lt;td&gt;{ticker}&lt;/td&gt;<br>              &lt;td&gt;{formatPrice(price)}&lt;/td&gt;<br>            &lt;/tr&gt;<br>          ))}<br>        &lt;/tbody&gt;<br>      &lt;/table&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export default App</pre><p>Here’s what is going on in the code above:</p><ol><li>formatPrice(price) This function takes in an integer and utilizes the Intl browser API to format it to standard US dollars currency format. The narrowSymbol of the currencyDisplay property specifies the use of the dollar sign ($) instead of (USD). You can read more about the Intl API <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl">here</a>.</li><li>The fetchStockPrice() function makes an HTTP request to the server using the browser&#39;s Fetch API. This request gets the current price from the server when the component mounts.</li><li>updateStockPrices(data) this function handles the events received from the server. The onmessage event handler will call this function and pass the data property of the event received from the server to it. This function will in turn update the app state using the setStockPrices() function.</li><li>The useEffect() hook will fetch the current prices of stock when the components mount by calling the fetchStockPrice() function. After which it will set up an EventSource connection with the server together with a handler that will respond anytime the client receives an event from the server.</li><li>The function component i.e App() returns an HTML table and the below is the content of the stylesheet that was used to apply basic styling to the table</li></ol><pre>/* App.css */</pre><pre>table {<br>  width: 80%;;<br>}<br>table, th, td {<br>  border: 1px solid black;<br>  border-collapse: collapse;<br>}<br>th, td {<br>  padding: 5px;<br>  text-align: left;<br>}</pre><h3>3.3 The NodeJS Server</h3><p>The Node JS server is an instance of an Express JS server that is configured to run on port 8000. It has two GET routes, /stocks route that supplies the current price of stocks and the /realtime-price route that supplies the update stock price in real-time. Below is the complete content of the Node JS server:</p><pre>/*server.js*/</pre><pre>const express = require(&quot;express&quot;);<br>const cors = require(&quot;cors&quot;);<br>const app = express();</pre><pre>app.use(cors());<br>const PORT = 8000;</pre><pre>const stocks = [<br>  { id: 1, ticker: &quot;AAPL&quot;, price: 497.48 },<br>  { id: 2, ticker: &quot;MSFT&quot;, price: 213.02 },<br>  { id: 3, ticker: &quot;AMZN&quot;, price: 3284.72 },<br>];</pre><pre>function getRandomStock() {<br>  return Math.round(Math.random() * (2 - 0) + 0);<br>}</pre><pre>function getRandomPrice() {<br>  return Math.random() * (5000 - 20) + 20;<br>}</pre><pre>app.get(&quot;/stocks&quot;, function (req, res) {<br>  res.status(200).json({ success: true, data: stocks });<br>});</pre><pre>app.get(&quot;/realtime-price&quot;, function (req, res) {<br>  res.writeHead(200, {<br>    Connection: &quot;keep-alive&quot;,<br>    &quot;Content-Type&quot;: &quot;text/event-stream&quot;,<br>    &quot;Cache-Control&quot;: &quot;no-cache&quot;,<br>  });<br>  setInterval(() =&gt; {<br>    res.write(<br>      &quot;data:&quot; +<br>        JSON.stringify({ ...stocks[getRandomStock()], price: getRandomPrice() })<br>    );<br>    res.write(&quot;\\n\\n&quot;);<br>  }, 10000);<br>});</pre><pre>app.listen(PORT, function () {<br>  console.log(`Server is running on ${PORT}`);<br>});</pre><p>Here’s what is going on in the code above:</p><ol><li><strong>Importation of needed libraries and instance of the server.</strong></li></ol><pre>const express = require(&quot;express&quot;);<br>const cors = require(&quot;cors&quot;);<br>const app = express();</pre><p>The express and cors libraries were imported into the app and an instance of an Express JS server (app)was created.</p><p>NB: You have to install express and cors libraries before you can import them. Run the command below to do so:</p><pre>$ yarn add express cors</pre><p>If you use NPM, replace yarn with npm.</p><ol><li><strong>Setting up of port and </strong><strong>cors configuration.</strong></li></ol><pre>app.use(cors());<br>const PORT = 8000;</pre><pre>const stocks = [<br>  { id: 1, ticker: &quot;AAPL&quot;, price: 497.48 },<br>  { id: 2, ticker: &quot;MSFT&quot;, price: 213.02 },<br>  { id: 3, ticker: &quot;AMZN&quot;, price: 3284.72 },<br>];</pre><pre>function getRandomStock() {<br>  return Math.round(Math.random() * (2 - 0) + 0);<br>}</pre><pre>function getRandomPrice() {<br>  return Math.random() * (5000 - 20) + 20;<br>}</pre><ul><li>The app is configured to listen to request from all origin using the cors library. This configuration is for testing purposes only, do not replicate in production. Also a constant, PORT was created to hold the value of the port that will eventually be passed to the listen method of the Express JS library.</li><li>A stocks array was created to hold information on companies and the prices of their respective stocks.</li><li>getRandomStock() is a function that returns a whole number between 0 and 2 which are the boundary indexes of the stocks array. Its purpose is to return a random stock index from the array of stocks.</li><li>getRandomPrice() returns a random decimal that is not greater than 5000. The purpose is to generate random prices that simulate the fluctuation in stock prices.</li></ul><ol><li><strong>The </strong><strong>/stock route.</strong></li></ol><pre>app.get(&quot;/stocks&quot;, function (req, res) {<br>  res.status(200).json({ success: true, data: stocks });<br>});</pre><p>A GET route was created to send out the current prices of stock.</p><ol><li><strong>The </strong><strong>/realtime-price route.</strong></li></ol><pre>app.get(&quot;/realtime-price&quot;, function (req, res) {<br>  res.writeHead(200, {<br>    Connection: &quot;keep-alive&quot;,<br>    &quot;Content-Type&quot;: &quot;text/event-stream&quot;,<br>    &quot;Cache-Control&quot;: &quot;no-cache&quot;,<br>  });<br>  setInterval(() =&gt; {<br>    res.write(<br>      &quot;data:&quot; +<br>        JSON.stringify({ ...stocks[getRandomStock()], price: getRandomPrice() })<br>    );<br>    res.write(&quot;\\n\\n&quot;);<br>  }, 10000);<br>});</pre><ul><li>writeHead() takes in the response status and the header configuration. Server-Sent Events must be of type text/event-stream.</li><li>setInterval() streams a new response/event to the client every 10 seconds (10000 milliseconds). The response contains a [JSON string](<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify</a>) of a stock and the updated price of the stock.</li></ul><ol><li><strong>Listening to request.</strong></li></ol><pre>app.listen(PORT, function () {<br>  console.log(`Server is running on ${PORT}`);<br>});</pre><p>Finally, the server is configured to listen to request on the predetermined port (8000). You can start the react app by navigating to the root of your app and running yarn start on your terminal. You can also start the server by running node server.js on your terminal from the root of the server&#39;s directory. Change yarn to npm if your installations were done using npm.</p><h3>3.4 Conclusion</h3><p>The primary aim of this article is to teach the fundamentals of Server-Sent Event and how to use it in a React application. While the Event-Source interface is native to the browser and can be utilized without using a library or framework; React was used in this article because of its popularity. There’s more to explore on Server-Sent Events e.g <a href="https://javascript.info/server-sent-events#event-types">event types</a>, <a href="https://javascript.info/server-sent-events#reconnection">reconnection</a> and more. Please feel free to explore once you are familiar with the basics. Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fbb83374f90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-a-build-real-time-react-app-with-server-sent-events-9fbb83374f90">How To A Build Real-time React App With Server-Sent Events</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Node.js by example — Part 2]]></title>
            <link>https://enirate.medium.com/learn-node-js-by-example-part-2-d27bc056e26f?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d27bc056e26f</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Sun, 08 Oct 2017 16:57:27 GMT</pubDate>
            <atom:updated>2017-10-08T16:57:27.205Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uTCUVm3UwUhzJaw8kH5DNQ.png" /></figure><p>This is the second part of the ‘Learn Node.js by example’ series. In this series, we are going to learn how to set up and use a MongoDB database and create RESTful API through which frontend clients will communicate with the serve.</p><h3>Mongoose and Body parser installation.</h3><p>We will navigate to our project folder on the command line and run npm install mongoose body-parser --save command to install mongoose and body parser.</p><p>Mongoose is a node package that manage connection to a MongoDB database, it also handle storage, retrieval and elimination of data.</p><p>We expect the front-end client to send data to the server at some point in time. Therefore, there is need to find a way to extract this information from the HTTP request object. Body parser will help us do that.</p><p>If you don’t have the latest version of Node.js installed on your machine you need to include the ` --save` flag to your npm install commands so that all the package being used in the project will be tracked in the package.json file.</p><h3>Setting up MongoDB</h3><p>Setting up a MongoDB locally can sometimes feel like drudgery. In order to avoid this we will host our database remotely on mLab. mLab is a MongoDB based database-as-a-service platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dXTDeuBV18mFhLp55B4d1w.jpeg" /></figure><p>Sign up and supply the necessary information to get started. MongoDB is a NoSQL database (basically, a database without tables). It stores data as JSON objects in a document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GXOQPGZh69cjQyj_oKppw.jpeg" /></figure><p>When you are done with registration, click on the create new button on the top right side of the page and follow the instruction to create a new MongoDB deployment / database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vcno8MYDMvdgpfHcMF4ZiQ.jpeg" /></figure><p>The name of your new MongoDB deployment should appear on the list of MongoDB deployments. Click on it and select the user tab on the new page to create a new user. You need to create a user to access the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKJltPzSjF4FUbdPHLdasQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nBh1ORpTGQoj0CtK60-ng.jpeg" /></figure><p>We can now connect to our database with the URL above the tabs by replacing &lt;dbuser&gt; with the username of the user we’ve just created and &lt;dbpassword&gt; with the password of the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccFVhavrYuYJD-DN1CdUDQ.jpeg" /></figure><h4>Creating Schema And Model.</h4><p>Before we start storing data in the database we need to define the structure of each unit of similar data set i.e the schema and a model that will enable us to perform database operation on the data set.</p><p>We start by creating a new file in the root directory, named models.js. Copy and paste the block of code below into the models.jsfile.</p><pre>var mongoose = require(&#39;mongoose&#39;);</pre><pre><em>// define schema as mongoose schema class</em></pre><pre>let Schema = mongoose.Schema;</pre><pre><em>// instantiate the schema class</em></pre><pre>let TodoSchema = new Schema({</pre><pre>todo_title: String,</pre><pre>todo_description: String,</pre><pre>todo_added_at: {type: Date, default: Date.now}</pre><pre>});</pre><pre><em>// create a model from the schema</em></pre><pre>let TodoModel = mongoose.model(&#39;TodoModel&#39;, TodoSchema);</pre><pre><em>// export model as a module</em></pre><pre>module.exports = TodoModel;</pre><p>In the code block above, we import the mongoose npm package into our file. This gives us access to the schema class which was used to define our schema by instantiating the Schema class and passing an object literal that contains the structure of our database to the constructor. We created a model from the schema and export our model as a Javascript module to make it reuse-able / accessible in other files.</p><p>Once we are done with this, we’ll import TodoModel in index.js file and connect to MongoDB. Behold the new look of index.js :</p><pre><em>// import express framework using es6 syntax</em></pre><pre>var express = require(&#39;express&#39;);</pre><pre><em>//import mongoose and TodoModel</em></pre><pre>var mongoose = require(&#39;mongoose&#39;);</pre><pre>var TodoModel = require(&#39;./models&#39;);</pre><pre><em>// create an instance of express called app</em></pre><pre>var app = express();</pre><pre><em>// specify the port number through which your app will be served</em></pre><pre>const PORT = 9000;</pre><pre><em>// connect to mongodb</em></pre><pre>mongoose.connect(&#39;mongodb://USERNAME_HERE:PASSWORD_HERE@XXXXXXXX.mlab.com:XXXXX/todo-list&#39;)</pre><pre><em>// use express get method to create a</em></pre><pre>app.get(&#39;/&#39;, function(req, res) {</pre><pre>res.status(200).send(&quot;Hello World!&quot;);</pre><pre>});</pre><pre><em>// listen to request sent to the port</em></pre><pre>app.listen(PORT, function() {</pre><pre>console.log(&quot;Server running on Port&quot;, PORT);</pre><pre>});</pre><p>Keeping our connection parameters in index.js file is a bad idea together with not providing a means of handling connection error. However trying to cater for all things we make this series longer than it is already. You can read more on how to connect to a MongoDB database with mongoose <a href="http://mongoosejs.com/docs/connections.html">here</a>.</p><p>Thanks for reading. Part 3, is the last part, please be on the lookout.</p><p>If you like this article, please, give a clap or ‘few’ to show appreciation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d27bc056e26f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Node.js by example — Part 1]]></title>
            <link>https://enirate.medium.com/learn-node-js-by-example-part-1-701544881ab?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/701544881ab</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Thu, 28 Sep 2017 16:14:12 GMT</pubDate>
            <atom:updated>2017-09-29T09:07:07.919Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5tNls9d1EKQcf_b3plQrw.png" /></figure><p>Javascript is everywhere. Gone are the days when you need to know Javascript and some other server side language before you can build a complete web application, thanks to Node.js.</p><p>Node.js is a platform that allows you to write Javascript on the server. With Node.js you can build scalable and fast applications, it is also perfect for data intensive applications.</p><p>SAP, LinkedIn, Netflix, GoDaddy and Microsoft are some of the popular companies that use Node.js</p><p>The aim of this tutorial is teach you how to setup a simple Node server, how to use node modules and node package manager and a gentle introduction to MongoDB. To achieve this, I’ll be building a very simple back-end for a Todo app, <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST </a>API endpoints will be utilized to expose resources to the client-side setup.</p><h3><strong>Getting Started.</strong></h3><p>Before you get started, you need to install node on your computer. If you haven’t, visit the <a href="https://nodejs.org/">Node.js website</a> and follow the instruction to download latest version of Node. To confirm if node has been installed, go to your command line and run node -v you should see the version of node installed on your system.</p><h4><strong>Node Package Manager.</strong></h4><p>After the installation of node, setting up our application is next, using the Node Package Manager (npm) commands.</p><p>So then, what is Node Package Manager?</p><p>Node package Manger is an entity that act as a store for node library or modules (both are code written by someone else so that you won’t re-invent the wheel if you want to solve a similar problem) and also allow the management of the modules e.g installation and updates via the command line interface.</p><p>To get started with npm in our shining new project, navigate to the project folder via command line (I name my project folder ‘TodoServer’) and run ``npm init`` in the Command line Interface to create a ‘package.json’ file in the project directory.</p><p>You will be asked some questions like the project name, project version and so on, in case you’ll like to go with the default value (which is not bad in this case) add — -yes flag to the npm init command like so npm init --yes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*-bJV1LBw0IcaIOcZyM_1FA.jpeg" /><figcaption>This is what I get after running ‘npm init’ command</figcaption></figure><p>Flags are options that are added to basic commands to make them perform extra task, in this case to give a default value for all the fields. Note, all valid Node Package Manager commands starts with ‘npm’.</p><p>Basically, the package.json file contains a meta data of your project (i.e the name of the project, the version, the license type, the name and version of node libraries being used in the project and so on). You can also define custom npm commands in the package.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9k2PSktmSvxLI721nr5Ww.jpeg" /><figcaption>My package.json file.</figcaption></figure><h4><strong>Getting started with express.</strong></h4><p>Express is a very light Node.js framework that enables developers to build web applications and APIs. We’ll use express to build API for theTodo app.</p><ol><li>Installation.</li></ol><p>Before you can use express, you need to install / download it as a npm package. To install express, navigate to the project directory and run the following command npm install express --save</p><p>If the installation is successful, it will reflect in the CLI and also in the package.json file. If you open the package.json file, express must have been added as a dependency together with a folder named ‘node_modules’ that will hold the source code for installed node modules or libraries. Also, a file named ‘package-lock.json’ named will be auto generated. The auto generated file give developers the power to switch between different states of node modules or libraries installed in a node project, it also ensure that developers working on a node project install exactly the same version of node modules or libraries, among other things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wb5_9cz0NBrr8vTP1AbA4g.jpeg" /><figcaption>Express has been added to package.json</figcaption></figure><p>2. Server setup</p><p>To setup express server, create a file named index.js. The name of the file is index.js because that is what we specified as the entry point to our node application in the package.json file.</p><p>Once this is done, copy and paste the code below into your index.js file</p><pre><em>// import express framework using es6 syntax</em></pre><pre>var express = require(&#39;express&#39;);</pre><pre><em>// create an instance of express called app</em></pre><pre>var app = express();</pre><pre><em>// specify the port number through which your app will be served</em></pre><pre>const PORT = 9000;</pre><pre><em>// use express get method to create a</em></pre><pre>app.get(&#39;/&#39;, function(req, res) {</pre><pre>res.status(200).send(&quot;Hello World!&quot;);</pre><pre>});</pre><pre><em>// listen to request sent to the port</em></pre><pre>app.listen(PORT, function() {</pre><pre>console.log(&quot;Server running on Port&quot;, PORT);</pre><pre>});</pre><p>With the block of code above, we’ve set up a simple express server. In the block of code above:</p><p>a. The express framework was imported as ‘express’, to make it accessible in the project. This was done using es5 require() function.</p><p>b. Creating an instance of express is next. It will be named ‘app’. A constant named ‘PORT’ is also created with the sole purpose of holding the value of the port on which the app will be served.</p><p>c. We use the get method of express to create a route which can only be accessed when a GET request is made to the server. Express has a lot of methods, including all the HTTP verbs i.e GET, PUT, DELETE, POST and PATCH . These methods can be utilized to create a very powerful server.</p><p>To create a route in express, after deciding the type of request that is allowed to be made to the route, a path will be specified and an ‘handler’ i.e a function that accepts two parameters, req and res . The handler function contains the logic or block of code that will be executed when a user navigate to this route, in this case the classic ‘Hello World!’ message together with HTTP status code of ‘200’ will be sent as HTTP response.</p><p>Basically, the req parameter is an object that represent HTTP request made to the server and contains properties like headers, body, request query string e.t.c.</p><p>Response from the server is handled by the response object represented by the res parameter. The response object will manage the HTTP response that express will send after receiving a request, This can be data, status code and the likes.</p><p>d. ‘listen()’ is an express method that accepts two parameters, the port number and an optional callback function. Listen will allow the express server to listen to request on a particular port.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=701544881ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The genuine reason why anybody can be a victim of HIV.]]></title>
            <link>https://enirate.medium.com/the-genuine-reason-why-anybody-can-be-a-victim-of-hiv-a74dedd34339?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a74dedd34339</guid>
            <category><![CDATA[world-health-organization]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[hiv]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 20:15:09 GMT</pubDate>
            <atom:updated>2017-07-11T20:18:44.595Z</atom:updated>
            <content:encoded><![CDATA[<p>Yesterday I released <a href="http://bit.ly/healthy-reminder">Healthy Reminder Bot</a>. A Facebook messenger bot that reminds people to go for monthly HIV test. The reason I made the bot is explained in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*RQcL6iTmB1tY4N4NYucXTg.jpeg" /><figcaption>screenshot of healthy reminder bot</figcaption></figure><p>Thanks to multitude of various Government and Non-Government organisations, <strong>general knowledge and awareness of HIV is at its peak</strong>. However based on my experience as a former executive of the <strong>Corp Peers and Educators Group</strong> (AKA Anti-HIV group) of the <strong>National Youth Service Corp</strong>, a lot of people think having safe sex will automatically make them immune from HIV, this is a big fallacy.</p><p>While sex is a major medium through which the virus is distributed, it is necessary to understand that person to person HIV infection occurs basically not because of sex but because some fluids from the body of an infected person comes in contact with your <a href="https://www.britannica.com/science/mucous-membrane">mucous membrane</a> or a damaged tissue in your body or injected directly into your blood stream (via contaminated blade, syringe etc). <strong>That is to say, you could possibly be infected with HIV by being social or through accidents</strong>.</p><p>Being social is wired into us as human beings and accidents are part of our daily lives.<strong> Therefore</strong>, <strong>we are all at risk of being infected with the virus because, you know, we are humans</strong>.</p><p>This is where getting tested regularly comes in, <strong>not because test is a cure but because it’s important if we are to win the war against HIV</strong>. The most important thing about test is the knowledge of HIV status it provide. <strong>Early test</strong> means <strong>early treatmen</strong>t and a <strong>relatively healthy life for an infected person through </strong><a href="http://www.who.int/hiv/topics/treatment/en/"><strong>drugs</strong></a><strong> that prevents the virus from progressing to the next stage and also stop onward transmission</strong>. It also means, people who are endangered by the infected person can start taking <a href="http://www.whatisprep.org/">drugs that prevents infection</a>.</p><p>While many of us recognize the importance of HIV test, we still struggle to get tested regularly. Even people whose lifestyle put them in danger of getting infected with HIV are guilty of this. ‘Out of sight is out of mind’, many of us, I believe, will <strong>remember</strong> to keep up with regular test if we can be <strong>reminded regularly</strong>. Everyone has a lot to think about these days.</p><p>Knowing that ‘out of sight is out of mind’, I have decided to create a simple and social Facebook <a href="http://bit.ly/healthy-reminder"><strong>messenger bot that will remind people to go for regular HIV test.</strong></a></p><p>Hello world, please accept<a href="http://bit.ly/healthy-reminder"> my humble donation</a> towards empowering people to lead a healthy lifestyle. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a74dedd34339" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to update to Angular’s latest CLI version @angular/cli]]></title>
            <link>https://enirate.medium.com/how-to-update-to-angulars-latest-cli-version-angular-cli-c7b1dce36476?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7b1dce36476</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Thu, 16 Feb 2017 13:00:07 GMT</pubDate>
            <atom:updated>2017-02-16T13:01:29.100Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s no longer news that Angular now have a new version of the command line (@angular/cli). The issue however is how can you update your command line interface to the latest version. This article will take you through the process of updating to the latest cli.</p><p><strong>THE RULE</strong></p><p>Remember that angular-cli is installed globally on your system, that means before you can update the version of your project, you need to update the global version first and here’s how to do it.</p><ol><li>Uninstall the old version with this command</li></ol><pre>npm uninstall -g angular-cli</pre><p>2. Clear the cache</p><pre>npm cache clean</pre><p>3. install the latest version</p><pre>npm install -g @angular/cli@latest</pre><p>And we are good. However, if you try to use angular commands like ng serve on your angular project you will discover that it will shoot an error at you, that is because the cli version of our project is yet to be updated.</p><p>Here’s how to update your project cli version:</p><ol><li>Delete your node_modules folder</li></ol><pre>rmdir /S node_modules #use rm -rf on mac</pre><p>if you have a dist(auto generated folder when you ‘ng build’ command) folder in your project you need to remove it like so:</p><pre>rmdir /S node_modules dist</pre><p>2. Install and add the latest version of @angular/cli to your package.json file as a development dependency.</p><pre>npm install --save-dev @angular/cli@latest</pre><p>3. Install node packages</p><pre>npm install</pre><p>4. Update</p><pre>ng update</pre><p>running the ‘update’ command will check for changes in the auto generated files that come with angular projects out-of-the-box and you be ask if you want to overwrite the existing with the new. You will also be prompted to choose from four options, y(yes), n(no), d(difference) and h(help). Choose with discretion.</p><p>If you run into any trouble, checkout angular cli <a href="https://github.com/angular/angular-cli/blob/master/CHANGELOG.md">change log</a>, but updating your dependencies to the latest version should solve most problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7b1dce36476" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 2 Life-cycle ‘simply’ explained]]></title>
            <link>https://enirate.medium.com/angular-2-life-cycle-simply-explained-a6f94c8b1864?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6f94c8b1864</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Fri, 30 Dec 2016 22:33:40 GMT</pubDate>
            <atom:updated>2017-01-01T19:57:53.383Z</atom:updated>
            <content:encoded><![CDATA[<p>In general terms life-cycle means the series of changes an entity passes through during it’s existence. Come to think of it, few years I sat beside two little guys in a public transport and overheard them talking about their heart desires.</p><p>One of the guy said that all he need in his life is a low-cost motorcycle and a rented room, what a mentality!</p><p>I believe if I can talk to that guy today he will have a better and rational ambition or dream because he would have moved from immaturity to maturity over time. That’s typical of human beings, we pass through different stages and experience changes in life, alias life-cycle.</p><p>Over to Angular 2, The components and directives of Angular 2 also have their own life-cycle, that is, they pass through different stages and experience changes in the course of their existence.</p><p>Angular does not only reveals these stages to us, it also gives us the ability to implement our own logic in any of these stages through <strong>life-cycle hooks method</strong>.</p><p>But seriously, why should you care?</p><p>How about using the OnInit method to log an external data to the console immediately the component is initialized, or watching for change in a data-bound input property of a component so as to do something when the data is equal to a particular value using the OnChanges method, how will you feel if you can stop a logic running at an interval with the power of the OnDestroy method just before the component using it get destroyed, so as to stop the logic from running when the soul our dear component is RIP(R=resting). The list is almost endless.</p><p>I can see you are in love, now, let us explain these life-cycle hooks interface.</p><ol><li><strong>OnChanges </strong>: Any logic attached to the method of this interface (In Angular 2 convention, methods of life-cycle interface are the name of the interface prefixed with ng using camelCase. e.g for OnChanges interface the name of the method will be ngOnChanges() ) will only be active when angular detects change in the input property of the component. Since this include when the property is being set, angular will therefore call this method before the ngOnInit method and will continue to call it when it detects any change. ngOnChanges method can also accept an argument of type SimpleChanges object that will hold the current and previous value of the components input properties.</li><li><strong>OnInit</strong> : Angular will call the method of this interface once, when the input property of the component get initialized.</li><li><strong>DoCheck</strong> : Angular will call the method of this interface when it discover any change that Mr. ngOnChanges fails to detect.</li><li><strong>AfterContentInit : </strong>While the preceding interfaces can be implemented in directives also, the AfterContentInit is a component only interface. Angular calls the method of this interface once, after ngDoCheck method, when the properties of a projected component is initialized.</li><li><strong>AfterContentChecked</strong> : Obviously it is also a component only interface. The method of this interface is called after ngAfterContentInit, anytime angular discovers change in the properties of a projected component.</li><li><strong>AfterViewInit</strong> : AfterViewInit is also a component only interface. Angular calls the method of this interface is once, when the properties of a view child is initialized. In simple terms, ViewChild(@ViewChild) is an angular decorator that helps us access the properties of a child component inside the parent component. You can read more about view child <a href="http://learnangular2.com/viewChild/">here</a>.</li><li><strong>AfterViewChecked</strong> : This is also for component only. The method of this Interface is a called anytime angular discovers change in the properties of a child component.</li><li><strong>OnDestroy </strong>: An interface for both directives and component. The method of this interface is called Just before the last breathe of a dying component and directives. Dear developer, this is an opportunity to clean up the mess created by your dying component or directive.</li></ol><p>BASICALLY…</p><p>For infant Angular 2 developers, projected component and child component might be giving you headache. To keep things basic, these are terms used for components that has been inserted into another component.</p><p>HOW</p><p>You can implement these interfaces in your components like so:</p><p>They all resides inside @angular/core, so you import them like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*YBmu-lnXfSn83btFYZwC7g.jpeg" /></figure><p>Then you will implement them in your component class declaration, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*w3msEiKoN5U6nBvmtkQbRw.jpeg" /></figure><p>Finally, create the corresponding method of the implemented interface and put your logic in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*nhmwo0ZIiIMXztlDHgaNRg.jpeg" /></figure><p>You can read more on Angular 2 lifecycle hooks <a href="https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html">here</a>. Thank You.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6f94c8b1864" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello Component : Introduction to Angular2 Component.]]></title>
            <link>https://enirate.medium.com/hello-component-introduction-to-angular2-component-1d0a05acf2f5?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d0a05acf2f5</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[ng2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Sat, 03 Dec 2016 07:01:09 GMT</pubDate>
            <atom:updated>2016-12-05T04:23:49.436Z</atom:updated>
            <content:encoded><![CDATA[<p>My assumption is that the readers of this post already know how to create and serve an Angular 2 project and have successfully created an Angular 2 app by running Angular 2 ‘ng new’ command like so,</p><pre>ng new your-new-project</pre><p>if you haven’t, ‘holup’, don’t kick yourself, read this <a href="https://helloangular.com/setting-up-a-basic-angular-2-project/">post</a> by <a href="https://medium.com/u/f7f8398c3660">Ire Aderinokun</a> then come back to this page to add knowledge to your knowledge.</p><p>Basically, angular 2 components are the smallest MVC unit of an angular 2 app i.e. a component is an entity that has its own View(HTML), model(i.e. Data) and Controller(Logic that controls the view). It is also represented by a custom HTML element that tells angular to render the component’s view wherever it find the component’s custom element.</p><p>Your typical Angular 2 component look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*tGdGejQCsMKlsRSn85iaMQ.jpeg" /></figure><p>The first line of code is self explanatory, it import the component decorator from the ‘core’ folder that resides inside the @angular folder.</p><p>so, what is component decorator?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*3JYzMMmXND0VzfnxJ44y9w.jpeg" /></figure><p>Basically, component decorator is like adjectives in English language, they tell angular framework more about the file in which they reside.</p><p>They tell angular that :</p><ol><li>The file has an angular component inside.</li><li>The name of the custom element that will render the component view in our application view will be called ‘app-root’.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*OwStPSMD20PDG1Zp6Xf0Zg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*kEjAZ09IzYC-A_Mae4napg.jpeg" /></figure><p>3. The markup language(HTML)/View of the component is located inside the app.component.html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*vVgWlmCGxcogWrgHp82k8w.jpeg" /></figure><p>4. The CSS to style our HTML/view is located inside the app.component.css file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*XTB5Zg1c5gCPei_Kmw9knA.jpeg" /></figure><p>If you pay attention to details, you’ll observe that there’s a ‘s’ after the ‘url’ in the styleUrls property. The square brackets that stands out, also shows that the property can accept an array of values. The implication of this is that your component HTML/view can be styled by multiple style sheet.</p><p>I hope this helps. Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d0a05acf2f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to remove an element from a JavaScript array.]]></title>
            <link>https://enirate.medium.com/how-to-remove-an-element-from-a-javascript-array-ce41d6ea259f?source=rss-2aae6dcffac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce41d6ea259f</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Eniola Lucas Fakeye]]></dc:creator>
            <pubDate>Fri, 02 Dec 2016 14:41:26 GMT</pubDate>
            <atom:updated>2016-12-02T14:57:51.871Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was working on an Angular2 project in order to get to grips with the framework, based on the nature of the project I need to manipulate an array of JavaScript object. Adding objects to the array was breeze but surprisingly, removing object completely from the array became tricky. There are popular method out there but most of them have one con or the other.</p><p>Using <a href="http://www.w3schools.com/jsref/jsref_filter.asp">.filter()</a> method, you will have a whole new array formed by elements that passes the test written in the method.</p><p><a href="http://www.w3schools.com/jsref/jsref_pop.asp">pop()</a> on the other hand will only remove the last element of the array.</p><p>Another method is the <a href="http://www.w3schools.com/jsref/jsref_map.asp">map()</a> method that also create another array from the original array by running a function (you’ll will pass a function through the .map() method) through the elements of the array. The new array will contain the result returned when each element is passed through the function.</p><p>Further more we have the<a href="http://www.w3schools.com/js/tryit.asp?filename=tryjs_array_shift"> shift()</a> method which do the reverse of what the pop() method does, it removes the first element from the array then shift the remaining element to a lower index i.e if the index of an element is 1 before the shift operation it will be assume a new index of 0 after the shift operation, but we can’t remove a middle element of our choice.</p><p><a href="http://www.w3schools.com/js/tryit.asp?filename=tryjs_array_delete">delete</a> operator is a hypocrite you cannot trust, it name doesn’t match its operation. Instead of deleting elements it only set their value to undefined thereby leaving ‘holes’ in your array.</p><p>Finally, we have the <a href="http://www.w3schools.com/jsref/jsref_splice.asp">splice()</a> method, it works like <a href="http://www.hypo.com.ng/">‘hypo’,</a> it remove completely the element from the array. You can use the splice method like so,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*mTMWpX8WP4C2fyIhKdhdkw.jpeg" /></figure><p>if you console log cool based on the screenshot above, you’ll get your array(new array won’t be formed), with 45 i.e. cleanly removed. You’re welcome. pretty easy, ehn?</p><p>PS: You need to know the index of the element in the array before you can remove it with the splice method, That’s why I use the indexOf() method to get the index of 45.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce41d6ea259f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>