<?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 Maher Alkendi on Medium]]></title>
        <description><![CDATA[Stories by Maher Alkendi on Medium]]></description>
        <link>https://medium.com/@maher.alkendi2?source=rss-6aca89e127a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u7fPDkwgJShOc9yQRZV1Mw.jpeg</url>
            <title>Stories by Maher Alkendi on Medium</title>
            <link>https://medium.com/@maher.alkendi2?source=rss-6aca89e127a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:40:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maher.alkendi2/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[You FINALLY got a job, now what?]]></title>
            <link>https://medium.com/@maher.alkendi2/you-finally-got-a-job-now-what-c5cba97e04f9?source=rss-6aca89e127a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5cba97e04f9</guid>
            <category><![CDATA[advice-and-opinion]]></category>
            <category><![CDATA[fresh-graduate]]></category>
            <category><![CDATA[work-culture]]></category>
            <category><![CDATA[career-development]]></category>
            <dc:creator><![CDATA[Maher Alkendi]]></dc:creator>
            <pubDate>Tue, 23 May 2023 12:38:06 GMT</pubDate>
            <atom:updated>2023-05-23T13:08:43.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-MTGBvzTY-2FBJWc0kocA.jpeg" /></figure><p>So you finally got a job! Congratulations 🎉. Now, how should you prepare for the new role in a manner that ensures success? What should you be doing on your first days? Of course, this depends on the job but I believe that there are key practical principles that can be followed in most jobs (most office jobs at least) to help with becoming effective at work. The items I mention in this article are practical actions that anyone can start implementing immediately.</p><p>This guide is for any fresh graduate or people with 1–2 years of experience, who want to make an impact at their job. I believe that if you take the principles from the points I list below, you will be able to increase your effectiveness at your job. Again, doesn’t matter the position! Whether you are a secretary, a receptionist, an accountant, or a web developer, I believe this guide will help you.</p><p>Before getting to the list, I would like to make it clear that I am assuming that you are a person that works hard and is not slacking at work so I did not list things like “work hard” below. Additionally, the list below is giving you some tactical points but don’t just take them blindly instead take the principles from them. Your specific context may vary.</p><h3><strong>Learn how your company makes money</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p56AU-kPkttHqE7WoWT-CA.jpeg" /><figcaption>Photo by: Karolina Grabowska</figcaption></figure><p>The first thing you should do, no matter your position, is to understand how your Company makes money. Your company provides some service to someone that pays them. What is that exactly and why? Find out!</p><p>Understanding how your company makes its money can lead to additional useful inquiries such as:</p><ul><li>How does my role help the company in that goal?</li><li>How can I through my role help?</li><li>Are there other things I could be doing?</li></ul><p>If you have the answers to the above, then you will learn how to be effective at work. Understanding what is important for the company will lead you to make smart decisions when doing your job. To make good decisions you need to have as much context as possible. That starts with understanding your company’s business.</p><p>But how can you get an understanding of your company and how it makes money? While there are various approaches and maybe I will write about this in the future. For now, see the second point below. I think it can be a good way to start.</p><blockquote>Example scenario: Let’s say you join a software development company. Understanding how the company generates revenue could involve researching their main sources of income, such as developing and selling software products or providing customized solutions for clients. By knowing this, you can align your work with the company’s goals and make informed decisions that contribute to their financial success. For example, as a web developer, you may focus on creating user-friendly and marketable websites that attract more clients and drive revenue for the company.</blockquote><h3>Be the note-taker!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIUWCZnIzohJ3z-AuoUInQ.jpeg" /><figcaption>Photo by: Christina Morillo</figcaption></figure><p>If you are new to the company, you probably are joining meetings where you don’t understand anything. So you keep quiet and pay attention to try and get an understanding of what is going on. Your plan is probably to attend these meetings enough times until you are able to contribute. This is not a bad strategy but I have a better one for you. Be the note-taker!</p><p>For every meeting that you attend, take the initiative by assuming the role of the note-taker. What this does is:</p><ul><li>Helps you understand what is going on in the meeting</li><li>Improves your writing</li><li>Makes you an important and integral part of every meeting (No one likes writing notes but they are very important!)</li></ul><p>I suggest you start taking notes and share them with your boss after each meeting. Then ask for feedback from them. Do they find value in this? What about the quality of writing? Is the content relevant? The more you write, the more you will get better and your understanding will get stronger.</p><p>Understanding the meetings will help you gain context on the project or particular situation which will help your decision-making. Note that this could be a good way to understand your business better.</p><blockquote>Example scenario: Imagine you’re a newly hired marketing assistant attending a team meeting about a new advertising campaign. By taking the initiative to be the note-taker, you actively engage in the discussion, capturing key points, action items, and ideas discussed during the meeting. Sharing these notes with your team and supervisor demonstrates your attentiveness and professionalism. Additionally, when reviewing the notes later, you may discover valuable insights or identify potential areas for improvement, which you can then propose to the team. Being the reliable note-taker helps you become an integral part of the decision-making process and fosters effective collaboration within the team.</blockquote><h3>Keep a diary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8h6x65MEKVfRyYhznT4FA.jpeg" /><figcaption>Photo by: Arina Krasnikova</figcaption></figure><p>This one is more straightforward and is very underrated. On a day-to-day basis, you are probably working on many different problems or tasks. It is important to keep track of them on a day-to-day basis. Why? well for the following reasons:</p><ul><li>Helps you track your progress and growth.</li><li>Helps you update your resume without needing to remember what you did a year ago.</li><li>Helps you make the case for getting a promotion.</li></ul><p>Keeping a diary may sound easy but it requires discipline. Some days you may be energetic and can write 10,000 words but others you will be so tired that you never want to look at your laptop (or notebook) again. So here is what I recommend:</p><ul><li>Try to write DAILY but I understand that “life happens” so don’t be tough on yourself if you miss a day or two. Daily habits build discipline.</li><li>Write the diary in bullet point format. I find these easier to write compared to paragraphs detailing the points.</li><li>Review your points weekly. So on a day-to-day basis don’t worry about the quality of what you write. focus on capturing your thoughts and insights, knowing that you can refine them during your weekly review.</li></ul><blockquote>Example scenario: Suppose you work in a sales role for a retail company. Keeping a diary allows you to document your daily interactions with customers, challenges you encountered, and successful sales strategies you implemented. For instance, you may record the techniques that helped you secure a high-value sale or notes on customer preferences and feedback. Over time, this diary becomes a valuable resource that helps you track your progress, identify patterns or trends, and reflect on your growth as a sales professional. When it comes time to update your resume or discuss your accomplishments with your manager, you can refer to your diary for specific examples of your achievements, effectively showcasing your contributions to the company’s success.</blockquote><p>Thats it! I believe that if you take into account the 3 points mentioned you will set yourself apart and excel in your job. Additionally, your growth will accelerate as you will be working in an efficient manner. Keep in mind that each point mentioned play into each other so combine them for maximum effect. Good luck!</p><p>FINAL point, I know that I did not detail the exact benefits of doing the above and that is because the benefits will show up to each individual differently. Depends on how you do it, what you learn, and the specifics of your job. OK, NOW I am done 😁!</p><p>Thanks for reading let’s connect on <a href="https://twitter.com/maheralkendi"><em>Twitter</em></a> and <a href="https://www.linkedin.com/in/maher-alkendi/"><em>LinkedIn</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5cba97e04f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn how Full-stack apps work by building a simple one using JavaScript (Part 2)]]></title>
            <link>https://itnext.io/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-2-45b42c1f2e84?source=rss-6aca89e127a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b42c1f2e84</guid>
            <category><![CDATA[axios]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Maher Alkendi]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 14:36:20 GMT</pubDate>
            <atom:updated>2018-12-17T08:29:12.775Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build a front-end app that can get data from a back-end API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AenJNna8ufix9ON-b9noJA.jpeg" /><figcaption>photo by <a href="https://unsplash.com/@rawpixel">rawpixel</a></figcaption></figure><p>In this tutorial we will build a simple form that can communicate with our fake weather API that we created in part one of this two part series. the form will accept a city name and return weather data related to the city. The app we are building is very simple but these concepts are the same concepts used to build large applications.</p><p>This is part two of this two part series. If you have not read part one you can check it out <a href="https://medium.com/@maher.alkendi2/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-1-38e237694012">here</a>.</p><h3>Step 1: Setup our project</h3><p>To follow along with this tutorial you will need the following:</p><ul><li>A Text Editor (I am using <a href="https://code.visualstudio.com/">VS Code</a>)</li><li>A browser (I am using <a href="https://www.google.com/chrome/">Chrome</a> but <a href="https://www.mozilla.org/en-US/firefox/new/">Firefox</a> should work fine)</li><li>The API built in <a href="https://medium.com/@maher.alkendi2/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-1-38e237694012">Part One</a> of this series</li></ul><p>Next lets get the starter files for this project. You can find them on <a href="https://github.com/Ma7eer/Fake-Weather-Form/tree/master">my Github</a>.</p><p>Once you’ve cloned or downloaded the files, open them on your Text Editor. This is the file structure you should see:</p><pre>/Fake-Weather-Form-Starter<br>  README.md<br>  index.html<br>  script.js</pre><p>We only have three files in there and only two of them are relevant to what we are doing. The script.js file is empty so lets start by opening up our index.html file. This is what you should see:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;</pre><pre>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot; /&gt;<br>  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>  &lt;title&gt;Fake Weather Data&lt;/title&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>  &lt;style&gt;<br>    body {<br>      font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif;<br>    }<br>    form {<br>      display: flex;<br>      /* flex-direction: column; */<br>      justify-content: center;<br>      align-items: flex-end;<br>      margin-top: 10%;<br>    }<br>    .form-item {<br>      display: flex;<br>      flex-direction: column;<br>      align-items: flex-start;<br>    }<br>    label, input, button {<br>      padding: 10px;<br>      margin-left: 10px;<br>    }<br>    label {<br>      padding-left: 0px;<br>    }<br>    .weather-info {<br>      display: flex;<br>      flex-direction: column;<br>      align-items: center;<br>    }<br>    .error-message {<br>      color: red;<br>      text-align: center;<br>    }<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>&lt;form&gt;<br>    &lt;div class=&quot;form-item&quot;&gt;<br>      &lt;label for=&quot;city&quot;&gt;City Name: &lt;/label&gt;<br>      &lt;input type=&quot;text&quot; placeholder=&quot;Enter a city name&quot; id=&quot;city&quot; name=&quot;city&quot; required&gt;<br>    &lt;/div&gt;<br>    &lt;button type=&quot;submit&quot;&gt;SUBMIT&lt;/button&gt;<br>  &lt;/form&gt;<br>  &lt;div class=&quot;error-message&quot;&gt;&lt;/div&gt;</pre><pre>&lt;div class=&quot;weather-info&quot;&gt;<br>    &lt;h1 class=&quot;cityName&quot;&gt;&lt;/h1&gt;<br>    &lt;h4 class=&quot;celsius&quot;&gt;&lt;/h4&gt;<br>    &lt;h4 class=&quot;fahrenheit&quot;&gt;&lt;/h4&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>The body of the html file simply contains a form with one input, a submit button, and a div containing three empty elements. These elements will display our data. In addition, we have a div below the form that will display any form related error messages.</p><p>I’ve added some styling inside the html head tag to make our form nicer to look at. Its not the best way to style or the best styling but it does the job. We care more about functionality than anesthetics in this tutorial. You can view the form by opening the index.html on your browser. If you do this is what you should see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*7liWT_uibN5NcGV_9ty2Nw.png" /></figure><p>Alright, now we are ready to write some code!</p><h3>Step 2: Build main form functionality</h3><p>We will be doing very simple DOM manipulation for this project, so we will be using vanilla JavaScript to do it. Open up your script.js file on your Text Editor and lets begin.</p><p>We want our form to retrieve data when it is submitted, so lets select our form then add an event listener for a <a href="https://developer.mozilla.org/en-US/docs/Web/Events/submit">submit event</a>.</p><pre>// Select our form<br>const form = document.querySelector(&#39;form&#39;);</pre><pre>// When form is submitted print &#39;submitted&#39; to the browser console<br>form.addEventListener(&#39;submit&#39;, function(e) {<br>  // prevent form default behavior<br>  e.preventDefault();<br>  console.log(&#39;submitted&#39;);<br>})</pre><p>For now all our form will be doing is printing out ‘submitted’ on our browser console. We are just making sure that the form works fine. If it does you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8r2CZlvKDNC1omdgzRp9Q.gif" /></figure><p>Nice! our form works. However, we want our form to have access to whatever the user inserts in the input. Lets select our text input then store its value in a variable. Anytime a user triggers an <a href="https://developer.mozilla.org/en-US/docs/Web/Events/input">input event</a> that variable needs to be updated.</p><pre>// Select text input<br>const textInput = document.getElementById(&#39;city&#39;);</pre><pre>// Store the value of the input in a variable<br>let cityName = textInput.value;</pre><pre>// When an input event is triggered update cityName<br>textInput.addEventListener(&#39;input&#39;, function(e) {<br>  cityName = e.target.value;<br>})</pre><pre>// Select our form<br>const form = document.querySelector(&#39;form&#39;);</pre><pre>// When form is submitted print &#39;submitted&#39; to the browser console<br>form.addEventListener(&#39;submit&#39;, function(e) {<br>  // prevent form default behavior<br>  e.preventDefault();</pre><pre>// print input value<br>  console.log(cityName);</pre><pre>// clear input<br>  textInput.value = &#39;&#39;;<br>})</pre><p>Our form now prints the value in the input when it is submitted then clears the text input value. Your app should now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1LVmOEW0sERuli3y4Gjrw.gif" /></figure><p>Perfect! now lets make a call to our API.</p><h3>Step 3: Fetch Data from Fake weather API</h3><p>Before we start fetching the data we need to make sure that our API is active. All you have to do in this case is go to your weather API directory and run it using node index.js. Once it starts you can leave it in the background and head back to our form.</p><p>There are many ways to make http requests using JavaScript. You could use <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest">XMLHttpRequest</a> or the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch API</a>, but in my case I prefer using <a href="https://www.npmjs.com/package/axios">axios</a>. There are no right answers here just personal preference.</p><p>To add axios to our app all we need to do is include the cdn in our html file.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br></pre><pre>...</pre><pre>  &lt;script src=&quot;<a href="https://unpkg.com/axios/dist/axios.min.js">https://unpkg.com/axios/dist/axios.min.js</a>&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In my case I added it just above my script tag for script.js .</p><p>We should now be able to use axios in our script.js file to make a request to our API</p><pre>// Select text input<br>const textInput = document.getElementById(&#39;city&#39;);</pre><pre>// Store the value of the input in a variable<br>let cityName = textInput.value;</pre><pre>// When an input event is triggered update cityName<br>textInput.addEventListener(&#39;input&#39;, function(e) {<br>  cityName = e.target.value;<br>})</pre><pre>// Select our form<br>const form = document.querySelector(&#39;form&#39;);</pre><pre>// When form is submitted print &#39;submitted&#39; to the browser console<br>form.addEventListener(&#39;submit&#39;, function(e) {<br>  // prevent form default behavior<br>  e.preventDefault();</pre><pre>// make request to our API<br>  axios.get(&#39;<a href="http://localhost:3000/weather/?city=&#39;">http://localhost:3000/weather/?city=&#39;</a> + cityName)<br>    .then(function(response) {<br>      console.log(response.data);<br>    })<br>    .catch(function(error) {<br>      console.log(error);<br>    })</pre><pre>// clear input<br>  textInput.value = &#39;&#39;;<br>})</pre><p>Now when the form is submitted we should get a response from our API printed on our browser console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3Elwva1XKPsTh5K32LcUQ.gif" /></figure><p>If you get the same result as the one shown above then congratulations! You are done with the bulk of this tutorial. Now all we need to do is display this data on our page instead of the browser console. In addition, we should get an error message when the user enters a city that isn’t in our database.</p><pre>// Select text input<br>const textInput = document.getElementById(&#39;city&#39;);</pre><pre>// Store the value of the input in a variable<br>let cityName = textInput.value;</pre><pre>// When an input event is triggered update cityName<br>textInput.addEventListener(&#39;input&#39;, function(e) {<br>  cityName = e.target.value;<br>})</pre><pre>// Select our form<br>const form = document.querySelector(&#39;form&#39;);</pre><pre>// When form is submitted print &#39;submitted&#39; to the browser console<br>form.addEventListener(&#39;submit&#39;, function(e) {<br>  // prevent form default behavior<br>  e.preventDefault();</pre><pre>// make request to our API<br>  axios.get(&#39;<a href="http://localhost:3000/weather/?city=&#39;">http://localhost:3000/weather/?city=&#39;</a> + cityName)<br>    .then(function(response) {<br>      // select elements<br>      let city = document.querySelector(&#39;.cityName&#39;);<br>      let celsius = document.querySelector(&#39;.celsius&#39;);<br>      let fahrenheit = document.querySelector(&#39;.fahrenheit&#39;);<br>      let errorMessage = document.querySelector(&#39;.error-message&#39;);</pre><pre>if (response.data.city) {<br>        city.innerHTML = &#39;City: &#39; + response.data.city;<br>        celsius.innerHTML = &#39;Temperature (C): &#39; + response.data[&#39;temperature (C)&#39;];<br>        fahrenheit.innerHTML = &#39;Temperature (F): &#39; + response.data[&#39;temperature (F)&#39;];<br>      } else {<br>        errorMessage.innerHTML = &quot;This city is not in our database&quot;<br>      }<br>    })<br>    .catch(function(error) {<br>      console.log(error);<br>    })</pre><pre>// clear input<br>  textInput.value = &#39;&#39;;<br>})</pre><p>The code above should yield the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Buzg-FK6b6mNZx7cF6eHiQ.gif" /></figure><p>Congratulations! If you got this far then you have successfully built an API and a front-end application that can fetch data from it. This was a very simple demo but I hope this inspires you to build something more robust and interesting.</p><p>If you have any questions or suggestions related to this post then feel free to comment below or find me on <a href="https://twitter.com/maheralkendi">my twitter</a> and leave me a message!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b42c1f2e84" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-2-45b42c1f2e84">Learn how Full-stack apps work by building a simple one using JavaScript (Part 2)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn how Full-stack apps work by building a simple one using JavaScript (Part 1)]]></title>
            <link>https://itnext.io/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-1-38e237694012?source=rss-6aca89e127a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/38e237694012</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Maher Alkendi]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 14:35:35 GMT</pubDate>
            <atom:updated>2019-01-15T09:22:45.726Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Learn how full-stack application works by building a simple fake weather API</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofMfrqFMfpaTH_RMvI_RQA.jpeg" /><figcaption>image by <a href="https://unsplash.com/@clemhlrdt">Clément H</a></figcaption></figure><p>This tutorial will walk you through the process of creating a simple fake weather API (fake because the data we are using is made up). After that we will build a simple front-end form and fetch data from our API. If you are new to Node and Express or are a front end developer that wants to get an idea of how the API’s you are fetching data from work, then this article is for you.</p><blockquote><a href="https://itnext.io/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-2-45b42c1f2e84">Part 2 — Build a front-end app that can get data from a back-end API</a></blockquote><p>Please note that what we are building is very simple but the concepts we touch on are the same ones used to build larger applications.</p><p>This is a two part series. You can find part two <a href="https://medium.com/@maher.alkendi2/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-2-45b42c1f2e84">here</a>. In this part we will only be the back-end part of our app</p><h3>Step 1: Project Setup</h3><p>Before you can dive deep into the tutorial you will need the following:</p><ul><li><a href="https://nodejs.org/en/">Node</a> (I am using v10.11.0)</li><li><a href="https://www.npmjs.com/get-npm">npm</a> (I am using 6.4.1)</li><li>A Text Editor (I am using <a href="https://code.visualstudio.com/">VS Code</a>)</li><li>A browser (I definitely recommend <a href="https://www.google.com/chrome/">Chrome</a> or <a href="https://www.mozilla.org/en-US/firefox/new/">Firefox</a>)</li></ul><p>Note that you do not need to have the exact version of Node and npm as I have for this to work. If you get any trouble getting these configured then please comment below and I will be happy to help. Once you have these setup its time to download or clone the starter code. You can find the files on <a href="https://github.com/Ma7eer/Fake-Weather-Api">my Github</a>. Don’t worry if you don’t understand what every file in the repository does, we will walk through each relevant file and its function.</p><h3>Step 2: Understand the starter files</h3><p>If you successfully cloned the starter code repository then this is the file structure you should have:</p><pre>/Fake-Weather-API<br>  .gitignore<br>  README.md<br>  data.js<br>  index.js<br>  package-lock.json<br>  package.json</pre><p>First things first, lets check out our package.json file</p><pre>{<br>  &quot;name&quot;: &quot;fake_weather_api_starter&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;Maher Alkendi&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;express&quot;: &quot;^4.16.4&quot;<br>  }<br>}</pre><p>This file contains the main information about our app. Note that we only have one dependency, which is express. Express is a Web Framework that makes it easy to build server-side applications using node. Read more about it <a href="https://expressjs.com/">here</a>.</p><p>Next we look at our index.js file</p><pre>const express = require(&#39;express&#39;); // import express<br>const app = express(); // initialize express</pre><pre>// Listen on port 3000<br>app.listen(3000, function() {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>All this code does is initialize an express server on port 3000. We will add more functionality to it as we go.</p><p>Now lets checkout the data.js file</p><pre>const fakeWeatherData = [<br>  {<br>    &#39;city&#39;: &#39;muscat&#39;,<br>    &#39;temperature (C)&#39;: &#39;37 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;98.6 F&#39;,<br>  },<br>  {<br>    &#39;city&#39;: &#39;tokyo&#39;,<br>    &#39;temperature (C)&#39;: &#39;16 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;61 F&#39;,<br>  },<br>  {<br>    &#39;city&#39;: &#39;moscow&#39;,<br>    &#39;temperature (C)&#39;: &#39;18 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;64 F&#39;,<br>  },<br>  {<br>    &#39;city&#39;: &#39;sydney&#39;,<br>    &#39;temperature (C)&#39;: &#39;17 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;63 F&#39;,<br>  },<br>  {<br>    &#39;city&#39;: &#39;london&#39;,<br>    &#39;temperature (C)&#39;: &#39;16 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;66 F&#39;,<br>  },<br>  {<br>    &#39;city&#39;: &#39;johannesburg &#39;,<br>    &#39;temperature (C)&#39;: &#39;24 C&#39;,<br>    &#39;temperature (F)&#39;: &#39;75 F&#39;,<br>  },<br>];</pre><pre>module.exports = fakeWeatherData;</pre><p>This file contains our fake weather data. It contains an array of objects called fakeWeatherData. Each object has a key for city, temperature in Celsius and temperature in Fahrenheit. At the bottom of the file we are exporting this array. Please note that this is fake data that I made up. In a real application this information will most likely be coming from a database.</p><p>In addition, we have our .gitignore files which ignores our node_modules folder.</p><p>OK these are the main files of the starter code. Now lets start building our fake weather API!</p><h3>Step 3: Build Fake Weather API</h3><p>Before we start writing any code, don’t forget to type npm install on your terminal to install all dependencies (in this case its only express). Now open up the index.js on your Text editor. Lets start by making our app return some json when it gets a GET request on the root directory.</p><pre>const express = require(&#39;express&#39;); // import express<br>const app = express();  // initialize express</pre><pre>// GET route<br>app.get(&#39;/&#39;, function(req, res) {<br>  res.send({&#39;hello&#39;: &#39;world&#39;})<br>})</pre><pre>// Listen on port 3000<br>app.listen(3000, function() {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>If you go to your terminal and type node index.js then open up your web browser and navigate to <a href="http://localhost:3000/">http://localhost:3000/</a> you should get back some json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzgOvqRWdb2NpXlU997e7Q.png" /></figure><p>You should be getting the same data but your json may not look as clean as the image above. If you want your browser to format the json data then check out this <a href="https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh">chrome extension</a>. Once you get it you should automatically be getting clean formatted json.</p><p>Lets now try to send out some of our fake weather data using our app. First we need to import the fake data from our data.js file. Then lets try and send out the first data item in our fakeWeatherData array when a GET request is made.</p><pre>const express = require(&#39;express&#39;);   // import express<br>const app = express();  // initialize express<br>const fakeWeatherData = require(&#39;./data.js&#39;); // import fake data</pre><pre>// GET route<br>app.get(&#39;/&#39;, function(req, res) {<br>  res.send(fakeWeatherData[0]);<br>})</pre><pre>app.listen(3000, function() {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>Once you’ve made these changes restart your express server by pressing ctrl + C then typenode index.js. You should see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQclaF67IWZGVEkADNGaoQ.png" /></figure><p>Nice! we now can send our fake data to a user when a GET request is made. Lets allow the user to input a city name and get the temperature data if its available. We do this by checking the URL query string and if it contains a parameter with a value that matches our city name, then we should return the data pertaining to that city.</p><p>If you are confused about URL query string you can check out this <a href="https://howto.caspio.com/parameters/parameters-as-query-string-values/">Link</a>. It will help you understand the different aspects of a URL.</p><p>In order to access the query string parameter using express we need to use req.query see the code below:</p><pre>const express = require(&#39;express&#39;);  // import express<br>const app = express();  // initialize express</pre><pre>// import our fake weather data<br>const fakeWeatherData = require(&#39;./data.js&#39;);</pre><pre>// GET route<br>app.get(&#39;/weather&#39;, function(req, res) {<br>  // if no city parameter exists  <br>  if (!req.query.city) {<br>    res.send({&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Please enter a city name&quot;})<br>  } else {<br>  res.send(fakeWeatherData[0])<br>  }<br>});</pre><pre>app.listen(3000, function() {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>Before I dissect the code above note that I changed the path to now be http://localhost:3000/weather. I did this to make our URL more descriptive.</p><p>If we do not supply our app with a query string with a parameter of city then we return a json error message. You can test this out by restarting your express server then going to the following path http://localhost:3000/weather/?city. In fact if you go to any /weather path you will get this error message. To fix this go to http://localhost:3000/weather/?city=ANYTHING. Now we see our city data again but we are only accessing one city’s information. Lets work on the logic to get the data based on the city parameter in the URL query string.</p><pre>const express = require(&#39;express&#39;);  // import express<br>const app = express();  // initialize express</pre><pre>// import our fake weather data<br>const fakeWeatherData = require(&#39;./data.js&#39;);</pre><pre>// GET route<br>app.get(&#39;/weather&#39;, function (req, res) {</pre><pre>// store the query string parameter in cityName variable<br>  let cityName = req.query.city.toLowerCase();</pre><pre>// Loop through our fake data array<br>  for (let i = 0; i &lt; fakeWeatherData.length; i++) {</pre><pre>// if no city parameter exists<br>    if (!cityName) {<br>      return res.send({&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Please enter a city name&quot;})<br>    } else if (cityName == fakeWeatherData[i].city.toLowerCase()) {<br>      return res.send(fakeWeatherData[i])<br>    }<br>  }</pre><pre>// if city parameter isn&#39;t in our fake data set<br>  res.send({&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;This city isn&#39;t in our database&quot;})</pre><pre>});</pre><pre>app.listen(3000, function () {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>The logic above is pretty simple. We are just accessing the city name typed by the user but getting it from our query string. This string is stored in req.query. Then we loop through our fake weather data array and check if we have any matches. If we do then our API should respond with the data related to the city.</p><p>OK now lets test our API! if we go to the path http://localhost:3000/weather/?city=tokyo. This is what we should see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nQZNPYVkVfXI3UW0j8Z4Q.png" /></figure><p>You can test it with any city in our fake data set and it should return the city data and if the city data isn’t available or no city was entered then we should get an appropriate error.</p><p>Although we are close to being done, we are not quite there yet. One last thing should be considered. We will be accessing this API through another application located in a different domain, so we will have to enable all cross-origin resource sharing. Luckily there is a node package that can help us with that called <a href="https://www.npmjs.com/package/cors">cors</a>. To install it we just type the following in our terminal:</p><pre>npm i --save cors</pre><p>Our finalpackage.json should now look like this:</p><pre>{<br>  &quot;name&quot;: &quot;fake_weather_api_starter&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;Maher Alkendi&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;cors&quot;: &quot;^2.8.4&quot;,<br>    &quot;express&quot;: &quot;^4.16.4&quot;<br>  }<br>}</pre><p>To enable all CORS requests we just have to add a few lines of code. Our finalindex.js file should now look like this:</p><pre>const express = require(&#39;express&#39;);  // import express<br>const app = express();  // initialize express<br>const cors = require(&#39;cors&#39;); // import cors package</pre><pre>// import our fake weather data<br>const fakeWeatherData = require(&#39;./data.js&#39;);</pre><pre>// Enable all CORS requests<br>app.use(cors());</pre><pre>app.get(&#39;/weather&#39;, function (req, res) {</pre><pre>// store the query string parameter in cityName variable<br>  let cityName = req.query.city.toLowerCase();</pre><pre>// Loop through our fake data array<br>  for (let i = 0; i &lt; fakeWeatherData.length; i++) {</pre><pre>// if no city parameter exists<br>    if (!cityName) {<br>      return res.send({&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;Please enter a city name&quot;})<br>    } else if (cityName == fakeWeatherData[i].city.toLowerCase()) {<br>      return res.send(fakeWeatherData[i])<br>    }<br>  }</pre><pre>// if city parameter isn&#39;t in our fake data set<br>  res.send({&quot;status&quot;: &quot;error&quot;, &quot;message&quot;: &quot;This city isn&#39;t in our database&quot;})</pre><pre>});</pre><pre>app.listen(3000, function () {<br>  console.log(&#39;listening on port 3000...&#39;);<br>})</pre><p>There we go! we just created a fake weather API. But this isn’t too exciting on its own. Lets create a simple UI to actually use this data.</p><p>If you made it this far I salute you! Keep in mind that this is only part one of this two part series. If you would like to see how we access the data, from the API we just created, from a front-end application. check out <a href="https://medium.com/@maher.alkendi2/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-2-45b42c1f2e84">part two</a>.</p><p>If you have any questions or suggestions then feel free to drop a comment below or send me a message on <a href="https://twitter.com/maheralkendi">my twitter</a> and I’ll be happy to respond!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38e237694012" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/learn-how-full-stack-apps-work-by-building-a-simple-one-using-javascript-part-1-38e237694012">Learn how Full-stack apps work by building a simple one using JavaScript (Part 1)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>