<?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 Mohamed Reda on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Reda on Medium]]></description>
        <link>https://medium.com/@Reda.Codes?source=rss-16a2a036380b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3YouFWITRlNa7UZueclXBA.png</url>
            <title>Stories by Mohamed Reda on Medium</title>
            <link>https://medium.com/@Reda.Codes?source=rss-16a2a036380b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:24:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Reda.Codes/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 Write a GraphQL Query]]></title>
            <link>https://javascript.plainenglish.io/how-to-write-a-graphql-query-9debe28df0d?source=rss-16a2a036380b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9debe28df0d</guid>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mohamed Reda]]></dc:creator>
            <pubDate>Fri, 23 Jun 2023 15:16:01 GMT</pubDate>
            <atom:updated>2023-06-23T15:16:01.164Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner’s guide to writing your first GraphQL query</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTmzfYQUkcXL1qyQS1vwCA.png" /></figure><p>Graphql, when you hear that name you probably imagine a tool that has to do with graphs and charts, that’s ok it happened to me as well. But, that’s not the case. Think of it as having your own data butler, you just have to ask it politely and it will bring all the data you need from your server.</p><h3>What is GraphQl?</h3><p>GraphQl acts like an adapter that sits on top of your API, doing the same job that a <a href="https://www.techtarget.com/searchapparchitecture/definition/RESTful-API">REST API</a> would do with much less work. It uses its own query language to communicate with the API and allows you to get all the data you need from one single POST request.</p><h3>How does it work?</h3><p>With its unique query language, GraphQl makes it easy for front-end developers to request multiple data from one single request. When you use GraphQl your API only has one single endpoint that is used for all your requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsExR9PIEDcGXeg8gP0hCQ.jpeg" /></figure><h3>GraphQl Server</h3><p><strong>If you would like to jump straight to the GraphQl client part </strong><a href="####GraphQl-Client"><strong>click here</strong></a></p><p>In order to use Graphql, depending on which programming language you like your API must be built with GraphQl-provided <a href="https://graphql.org/code/">libraries</a>. For this article, I have created a basic GraphQL API Using <a href="https://www.apollographql.com/">Apollo</a> GraphQL server That allows you to create your own Graphql server in Three easy steps:</p><h4>Step 1: Prepare the environment</h4><ul><li>Create an empty folder.</li><li>Use your favorite terminal and Initialize a new Node.js project.</li></ul><pre>npm init --yes</pre><ul><li>To run Apollo you need to install two dependencies graphql, @apollo/server, and nodemon to automatically restarts your node application.</li></ul><pre>npm install @apollo/server graphql nodemon</pre><ul><li>In your package.json file add the following line to be able to import packages.</li></ul><pre>{<br>  &quot;type&quot;: &quot;module&quot;<br>}</pre><h4>Step 2: index.js file</h4><ul><li>In your root folder create a. index.js file and import the following packages.</li></ul><pre>import {ApolloServer } from &#39;@apollo/server&#39;;<br>import { startStandaloneServer } from &#39;@apollo/server/standalone&#39;;</pre><ul><li>Create a mockup database.</li></ul><pre>const authors = [<br>  { id: &#39;1&#39;, name: &#39;J. K. Rowling&#39; },<br>  { id: &#39;2&#39;, name: &#39;George R. R. Martin&#39; },<br>  { id: &#39;3&#39;, name: &#39;Stephen king&#39; },<br>];<br>const books = [<br>  { id: &#39;1&#39;, title: &#39;Fantastic Beasts and Where to Find Them&#39;, authorId: &#39;1&#39; },<br>  { id: &#39;2&#39;, title: &#39;A Game of Thrones&#39;, authorId: &#39;2&#39; },<br>  { id: &#39;3&#39;, title: &#39;Fairy Tale&#39;, authorId: &#39;3&#39; },<br>  { id: &#39;4&#39;, title: &#39;Harry Potter and the Philosopher Stone&#39;, authorId: &#39;1&#39; },<br>  { id: &#39;5&#39;, title: &#39;A Clash of Kings&#39;, authorId: &#39;2&#39; },<br>];</pre><h4>Step 3: Creating GraphQL schema and the resolvers</h4><p><strong>what is a GraphQl schema?</strong></p><p>A schema is the heart of your GraphQL API that will help you interact with your data and It consists of types, queries, and mutations.</p><p><strong>Types</strong> are the building blocks of a GraphQl schema. they define all types of data that can be queried or mutated through your API.</p><p><strong>Queries</strong> are pre-defined templates to query data from your API it describes the data that is required and the shape of the response that is expected, you can think of it as the GET request.</p><p><strong>Mutations</strong> are similar to queries and they are used to modify data on the server.</p><p><strong>Let’s create our schema</strong></p><p>In the same file we will create our schema that contains two types one for our authors and the other one for our books, we will also have a Query type to handle all the data retrieving requests. Finally, a mutation type is used to handle the addition of new authors and books.</p><pre>const typeDefs = `<br>  type Author {<br>    id: ID!<br>    name: String!<br>    books: [Book!]<br>  }<br><br>type Book {<br>    id: ID!<br>    title: String!<br>    author: [Author]!<br>  }<br>  type Query {<br>    author(id: ID): [Author]<br>    authors: [Author!]!<br>    book(id: ID): [Book]<br>    books: [Book!]!<br>  }<br>  type Mutation {<br>    addAuthor(name: String!): Author<br>    addBook(title: String!, authorId: String!): Book<br>  }<br>`;</pre><p>If you noticed in the Author type we have [Book!] as the book type and not a string, what that does is it creates a relationship between the Author type and the book type so we can get a list of all the books that Author has written.</p><p><strong>Resolvers</strong></p><p>Resolvers are functions that execute once a query or a mutation is triggered.</p><pre>const resolvers = {<br>Query: {<br>    author: (parent, { id }) =&gt; authors.find(author =&gt; author.id === id)? [authors.find(author =&gt; author.id === id)] : new Error(`Author with ID ${id} does not exist`),<br>    authors: () =&gt; authors,<br>    book: (parent, { id }) =&gt; [books.find(book =&gt; book.id === id)],<br>    books: () =&gt; books,<br>  },<br>Author: {<br>    books: (author) =&gt; {<br>    return books.filter(book =&gt; book.authorId === author.id)<br>    },<br>},<br>Book: {<br>    author: (book) =&gt; {<br>    return authors.filter(author =&gt; author.id === book.authorId)<br>    },<br>},<br><br>Mutation: {<br>  addAuthor(parent, {name}) {<br>    const newAuthor = { id: authors.length + 1, name: name };<br>    authors.push(newAuthor);<br>    return newAuthor<br>  },<br>  addBook(parent, {title, authorId}) {<br>    const author = authors.find(author =&gt; author.id === authorId);<br>    if (author) {<br>        const newBook = { id: books.length + 1, title: title, authorId: authorId };<br>        books.push(newBook);<br>        return newBook;<br>    } else {<br>        throw new Error(`Author with ID ${authorId} does not exist`)<br>    }<br>  }<br>}<br>};</pre><p>If you notice we also have Author and Book resolvers I know it’s a bit confusing but don’t worry <strong>I Got You</strong>.</p><p>If you go back to our schema we have two relations one is between the Author type and books and the other one is between the Book type and the authors, we call these nested queries, and for every nested query, you are supposed to create its own logic.</p><p><strong>Starting the server</strong></p><p>Now everything is ready you just need to create a new server instance and start your app.</p><pre>const server = new ApolloServer({<br>  typeDefs,<br>  resolvers,<br>});</pre><pre>const { url } = await startStandaloneServer(server, {<br>  listen: { port: 4000 },<br>});</pre><p>Congratulation you just created your first GraphQl server to start it run the following command</p><pre>nodemon ./index.js localhost 4000</pre><h3>Apollo playground</h3><p>If you head to localhost:4000 you’ll find an interactive playground that allows you to query and test your API easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SM64HZByEK7jKgjZV__Dcw.png" /></figure><h3>Your first GraphQL query</h3><p>Graphql playground provides an interactive documentation section for exploring and testing GraphQL queries, and mutations.</p><p>It shows you all the data types you’ve created and how you can test every query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*YNuGhh7aMKTX07rWln9Sdg.png" /></figure><h3><strong>Query structure</strong></h3><p>We can split the query into Four sections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*2icMQgT5PYOfGq69dkqkqQ.png" /></figure><p>1. The root type is where we can choose whether to perform a query or a mutation.</p><p>2. The data that we want to get or add.</p><p>3. The filter if available or the input if we are adding new data.</p><p>4. The return structure.</p><p>So, if we run the query above in our playground we will get the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9GI9MmcZSQjzUp8-xiL4g.png" /></figure><p>Congratulations you just built your first GraphQL severe.</p><h3>GraphQl Client</h3><p>To show you how you can request data from a GraphQl API we going to build a simple app using <a href="https://react.dev/">React</a> and <a href="https://www.apollographql.com/docs/react/">Apollo client</a>.</p><p>Also, don’t worry if you did not build your own GraphQl server, because for this section we will be using <a href="https://rickandmortyapi.com/graphql">Rick and Morty</a> API.</p><h4>Prepare the environment</h4><ul><li>Create a new React project locally with:</li></ul><pre>npx create-react-app react-apollo-graphql-client</pre><ul><li>Installing all the dependencies.</li></ul><pre>npm install @apollo/client graphql</pre><p>To make the project a little bit more fun I will also install <a href="https://tailwindcss.com/docs/guides/create-react-app">TailwindCSS</a> feel free to skip this if you are good with Vanilla CSS.</p><p>I like to delete all React demo-related files to have a clean start.</p><pre>├── node_modules/   # node stuff that we shouldn&#39;t touch<br>├── public/   # public folder<br>|   ├── media/  <br>|   ├── index.html   <br>├── src/   # here is where the magic happens<br>|   ├──  components/ <br>|   ├──  App.jsx # No! here is where the magic happens<br>|   ├──  index.css<br>|   └──  index.js<br>├── .gitignore<br>├── package-lock.json<br>├── package.json<br>├── tailwind.config #Tailwind config file<br>└── README.md</pre><h4>Initializing ApolloClient</h4><p>In your index.js file import the following packages.</p><pre>import { ApolloClient, InMemoryCache, ApolloProvider} from &#39;@apollo/client&#39;;</pre><p>Next, we’ll initialize <strong>ApolloClient</strong>, passing its constructor a configuration object with the uri and cache fields.</p><pre>const client = new ApolloClient({<br>  uri: &#39;https://rickandmortyapi.com/graphql&#39;,<br>  cache: new InMemoryCache(),<br>});</pre><p>Finally, we can wrap our App component with the <strong>ApolloProvider</strong> and pass it the client.</p><pre>const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));<br>root.render(<br>    &lt;ApolloProvider client={client}&gt;<br>      &lt;App /&gt;<br>    &lt;/ApolloProvider&gt;,<br>);</pre><h4>Fetching the data with useQuery</h4><p>After successfully setting up <strong>ApolloProvider</strong>, you can start requesting data with <strong>useQuery</strong>.</p><p>First, we need to import <strong>useQuery</strong> to get the data and <strong>gql</strong> to create our formatted query from ‘@apollo/client’.</p><pre>import { useQuery, gql } from &#39;@apollo/client&#39;;</pre><p>Create a simple query to get the data we need. In this case, I’ll be requesting all the characters and their related information, including the total count of all the characters and the number of the next page to handle pagination.</p><pre>const GET_DATA = gql`<br>    query {<br>        characters(page:1) {<br>            info {<br>            count,<br>            next<br>            },<br>            results {<br>            id,<br>            name,<br>            species,<br>            image<br>            }<br>        }<br>    }<br>`;</pre><p>To get the data just call useQuery and pass it a GraphQL query string.</p><p>useQuery returns an object from Apollo Client that contains loading, error, and data properties we can use to render our UI. In this case, I will just log it into the console.</p><pre>const { loading, error, data } = useQuery(GET_DATA);<br><br>if (loading) return &lt;p className=&#39;text-white text-lg font-mono font-bold text-center&#39;&gt;Loading...&lt;/p&gt;;<br>  if (error) return &lt;p&gt;charactersError : {error.message}&lt;/p&gt;;<br>  console.log(data.characters);<br>  return &lt;p&gt;hello world&lt;/p&gt;;</pre><h4>Displaying the data in our browser</h4><p>To display the data I’ll create a simple component named DisplayCharacters in our components folder that takes a data prop and map though it to show us all the characters.</p><pre>export default function DisplayCharacters({ data }) {<br>  <br>  return (<br>    &lt;div className=&quot;flex lg:w-10/12 sm:w-full mx-auto flex-wrap justify-between font-mono&quot;&gt;<br>        {<br>            data.characters.results.map((ch) =&gt; (<br>                &lt;div key={ch.id} className=&quot;lg:w-1/4 md:w-1/3  sm:w-1/2&quot;&gt;<br>                    &lt;div className=&quot;bg-white rounded-xl p-5 m-5&quot;&gt;<br>                        &lt;img className=&quot;rounded-xl pb-4 drop-shadow-2xl&quot; width=&quot;400&quot; height=&quot;250&quot; alt=&quot;location-reference&quot; src={`${ch.image}`} /&gt;<br>                        &lt;h3 &gt;Name: {ch.name}&lt;/h3&gt;<br>                        &lt;p&gt;Species: {ch.species}&lt;/p&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            ))<br>        }<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Next, I’ll Import DisplayCharacters to my App.jsx file along with useState to handle pagination.</p><p>Then I’ll create a page variable that can be passed to our query and then we can increment that number to get the next page.</p><pre>import { useState } from &#39;react&#39;;<br>import { useQuery, gql } from &#39;@apollo/client&#39;;<br>import DisplayCharacters from &#39;./components/DisplayCharacters&#39;<br><br>function App() {<br>  let [page, setPage] = useState(1);<br>  const GET_DATA = gql`<br>      query {<br>          characters(page:${page}) {<br>              info {<br>              count,<br>              next<br>              },<br>              results {<br>              id,<br>              name,<br>              species,<br>              image<br>              }<br>          }<br>      }<br>  `;<br>  const { loading, error, data } = useQuery(GET_DATA);<br>  if (loading) return &lt;p className=&#39;text-white text-lg font-mono font-bold text-center&#39;&gt;Loading...&lt;/p&gt;;<br>  if (error) return &lt;p&gt;charactersError : {error.message}&lt;/p&gt;;<br>  console.log(data.characters);<br>  return (<br>    &lt;&gt;<br>      &lt;div&gt;<br>        &lt;h1 className=&#39;text-5xl text-center m-5 mb-10 font-bold text-white&#39;&gt;Rick and Morty Characters&lt;/h1&gt;<br>        &lt;DisplayCharacters data={data}/&gt;<br>      &lt;/div&gt;<br>      &lt;div className=&#39;flex justify-center m-10&#39;&gt;<br>        &lt;div className=&#39;&#39;&gt;<br>              {<br>                  page === 1 ? &#39;&#39; : &lt;button className=&#39;bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-l&#39; onClick={() =&gt; {setPage(page-=1)}}&gt;PREV&lt;/button&gt;<br>              }<br>              {<br>                  data.characters.info.next ? &lt;button className={page=== 1? &#39;bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded&#39;: &#39;bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-r&#39;} onClick={() =&gt; {setPage(page+=1)}}&gt;NEXT&lt;/button&gt; : &quot;&quot;<br>              }  <br>        &lt;/div&gt;  <br>      &lt;/div&gt;<br>    &lt;/&gt;<br>  );<br>}<br>export default App;</pre><p>That’s it now our app should look something like this.</p><p>Check it out live <a href="https://reda-codes.github.io/graphql-post/">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WbWtAJN3cBGfW2tDJMxdVw.png" /></figure><p>Great job on making it this far. I appreciate you taking the time to read our article, I’m sure that you learned a ton of new stuff.</p><h3>Resources</h3><p>Project repository: <a href="https://github.com/Reda-codes/graphql-post">https://github.com/Reda-codes/graphql-post</a></p><p>Live site: <a href="https://reda-codes.github.io/graphql-post/">https://reda-codes.github.io/graphql-post/</a></p><p>Apollo documentation: <a href="https://www.apollographql.com/docs/">https://www.apollographql.com/docs/</a></p><p>TailWindCSS documentation: <a href="https://tailwindcss.com/docs/installation">https://tailwindcss.com/docs/installation</a></p><p>Rick &amp; Motry API: <a href="https://rickandmortyapi.com/graphql">https://rickandmortyapi.com/graphql</a></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9debe28df0d" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-write-a-graphql-query-9debe28df0d">How to Write a GraphQL Query</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ecolio, A Platform For Every School]]></title>
            <link>https://medium.com/@Reda.Codes/ecolio-a-platform-for-every-school-76d3c463f491?source=rss-16a2a036380b------2</link>
            <guid isPermaLink="false">https://medium.com/p/76d3c463f491</guid>
            <dc:creator><![CDATA[Mohamed Reda]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 18:15:19 GMT</pubDate>
            <atom:updated>2023-03-08T18:15:19.970Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*kdT-GdVlr0IEAn8e0f4zMw.png" /></figure><p>Ecolio is a school Content Management System (CMS) MVP that has been thoughtfully designed to assist schools in managing their students, instructors, and staff members. Ecolio empowers educational institutions to create and manage user accounts, including both instructors and students, and develop classes for them to participate in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RwqeDCP9elTRANv55LCgQ.png" /></figure><p>The idea for Ecolio was born out of a chance encounter when I was randomly searching for various CMSs. I noticed that there was a lack of practical solutions specifically targeted toward the needs of schools. This realization inspired Me to create Ecolio, a platform that can help every school.</p><p>At its core, Ecolio MVP offers several essential features to schools, such as:</p><h4>Multiple Users Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iGnTOBNAl8zr8CAxXVfdw.png" /><figcaption>Login Page</figcaption></figure><p>Thanks to Auth0, we were able to implement a feature that allows different user types to log in from the same portal and access different dashboards. Auth0 provides a secure and scalable identity management platform that enables us to easily authenticate and authorize users based on their roles or permissions. This means that users can log in with different credentials and get access to features or data that are specific to their role or permissions. For example, a teacher can log in and see a dashboard with student lists and grades, while an administrator can log in and access a dashboard with more administrative features like user management and reporting. This feature allows us to provide a personalized user experience that is tailored to the specific needs of each user type, improving the overall usability and efficiency of our platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGmzFAjGnCQEzGPN48tlZw.png" /></figure><h4>Public Announcements</h4><p>Ecolio’s public announcements feature allows school staff to share important information, updates, and announcements with all students and instructors in one place. With this feature, staff members can easily create public announcements about school events, instructions, or even a simple happy birthday message to someone, and share them with the entire school community. This feature helps to keep everyone informed and engaged, creating a sense of community and school spirit. Students and instructors can view public announcements on their dashboards and stay up-to-date on the latest school news and events. The public announcement feature is an excellent tool for school staff who want to keep everyone informed and connected, ensuring that everyone is on the same page and working towards a common goal.</p><h4>Students Private Notes</h4><p>Ecolio’s private notes feature allows instructors to share individualized feedback and comments with each student, ensuring that they receive personalized support and guidance. With this feature, instructors can create private notes for each student, providing them with specific feedback on their academic progress and identifying areas where they may need additional support. Instructors can also use private notes to recognize their students’ achievements, encourage them to continue working hard, and help them develop the skills they need to succeed. By enabling instructors to share private notes with each student, Ecolio helps to foster a supportive learning environment that encourages students to reach their full potential. The private notes feature is a valuable tool for instructors who want to make a positive impact on their student’s academic success and personal growth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*9YVRaFUf8sFsqttQh-oAjQ.png" /></figure><h4>Homework Tracking</h4><p>Ecolio’s homework tracking feature allows instructors to keep a record of the homework assigned to students, enabling them to monitor their progress and ensure that they are meeting their academic goals. With this feature, instructors can easily assign different homework to multiple classes. In the future, this feature will evolve to allow instructors to set due dates and track the completion status of each task. Students can view their assignments, complete them, and mark them as done, providing them with a sense of accomplishment and ownership of their education. Instructors will also be able to add individual notes with each student’s assignment, providing personalized feedback and ensuring that students receive the support they need to succeed. The homework tracking feature is an essential tool for instructors and students alike, helping to promote accountability and academic achievement.</p><h4>Project Structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnfxib8MmCUNuuOTbrfhfA.jpeg" /></figure><p>The app consists of multiple microservices that work together to deliver a fully functioning product with minimal technical debt.</p><p>The backend API is built using flask which is a syntax-friendly framework also ideal for a quick MVP build due to the short period I had.</p><p>The frontend client was built using react due to its nature of having reusable components that different types of users use. Also, there is nothing better than the amazing and super flexible MongoDB to prototype with.</p><p>Finally, for the authentication, we used Auth0 and the huge amount of features that are available out of the box to make the app secure and focus more on building the app.</p><h4>Information flow</h4><p>when a user signs in, the React client sends the user’s credentials to Auth0 to verify if the user exists. If the user is verified, Auth0 provides the client with an access token that can be used for subsequent requests to the API. This eliminates the need for the client to obtain a separate access token for the API since the same access token provided by Auth0 can be used for the API.</p><h4>Project Deployment</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9o43keWNp-ownjlfZq2oIA.png" /></figure><h4>Deployment process</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*HtXefZhkTt02K7CkhSa9hg.png" /></figure><p>The project deployment consists of two automated Jobs. Once a repository is updated we use GitHub action to deploy our new code following the steps below:</p><p><strong>Creating the Docker image:</strong></p><ul><li>Building the Docker Image</li><li>Push the image to the docker Hub</li></ul><p><strong>Deploying to server:</strong></p><ul><li>Log to our server</li><li>Pull the new image</li><li>Stop the container</li><li>Delete the container</li><li>Run a new one with the newly pulled image</li></ul><p>The Ecolio team plans to introduce even more features, including class attendance management, file sharing, in-app messaging, a school calendar, and administrative contact. Additionally, parent accounts will be able to access the platform with their own accounts, enabling them to keep themselves informed of their child’s academic progress.</p><p>With Ecolio, schools can streamline their administrative tasks, allowing them to focus on providing the best possible education to their students. Ecolio is an indispensable tool for educational institutions of all sizes, and it is certain to have a significant impact on the education industry as a whole.</p><p>If you are interested in knowing more about this project check out the resources below or contact me at hello@reda.coffee</p><p><a href="https://github.com/Reda-codes/ecolio">GitHub - Reda-codes/ecolio: ecolio is a platform dedicated for schools to help manage their students.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76d3c463f491" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type google.com in your browser and press Enter]]></title>
            <link>https://medium.com/@Reda.Codes/what-happens-when-you-type-google-com-in-your-browser-and-press-enter-fe41e4427b92?source=rss-16a2a036380b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe41e4427b92</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[intenet]]></category>
            <category><![CDATA[network]]></category>
            <dc:creator><![CDATA[Mohamed Reda]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 17:50:07 GMT</pubDate>
            <atom:updated>2023-01-08T17:50:07.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y41CE_3_XSu6BV81" /><figcaption>Photo by <a href="https://unsplash.com/@jjying?utm_source=medium&amp;utm_medium=referral">JJ Ying</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When you type something in the search bar it happens so fast like if it already knew what you were looking for but behind the scenes a lot has happened to retrieve the data that you were looking for.</p><p>In this article I’ll explain to you how visiting a website such as “google.com” is way complicated than what you think.</p><p>When you type <strong><em>google.com</em></strong> into your web browser and hit enter, a series of complex events happen behind the scenes to bring that page to your screen, even though it feels instantly is was not always like that.</p><h4><strong><em>Short story time:</em></strong></h4><p><strong>NOTE: If you don’t want to hear my story just skip this paragraph</strong></p><p><em>As I said, long time ago when the computer era has just started It was very normal to wait for a website to get generated those days the average speed of the interned was about 512kb where I live, yeah that number looks very big but in today’s terms that’s about half a megabit. But, at that time websites were very simple mostly text and you couldn’t do anything just read, chat or watch videos no ticktock, no Instagram and no multiplayer games.</em></p><p><em>Nowadays we have access to a blistering fast interned at the palm of our hands, which have allowed us to make wonders.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lVcMQtTlrBm-P5hEjdO0Dw.jpeg" /></figure><h4><strong>DNS request</strong></h4><p>First, your computer sends a request to the Domain Name System (DNS) which resolves the domain name (google.com) to an IP address that is assigned to it. The DNS servers act as a directory of the internet, its main job is to translate domain names to the corresponding IP addresses of the servers where the website is hosted. In some cases the ip address assede to a domain name if for the load balancer that is</p><p>Once the IP address is obtained, the computer establishes a connection to the server using the Transmission Control Protocol (TCP). TCP is a protocol that ensures that data is transferred reliably and in the correct order between the computer and the server.</p><h4><strong>Firewall</strong></h4><p>Before the data can be transferred, it must pass through any firewalls that are in place to protect the server. A firewall is a security system that controls incoming and outgoing network traffic based on predetermined security rules.</p><h4><strong>SSL</strong></h4><p>Once the connection is established and the data has passed through the firewall, the server uses the Secure Sockets Layer (SSL) protocol to encrypt the data being transferred. SSL creates a secure, encrypted connection between the server and the client (your computer) to protect sensitive information, such as login credentials or credit card information.</p><h4><strong>load balancer</strong></h4><p>Once the connection is secure, the request is sent to a load balancer. A load balancer is a device that distributes incoming traffic across multiple servers to ensure that no single server becomes overloaded. This helps to ensure that the website remains fast and responsive for all users.</p><h4><strong>Web server, Application server, Database</strong></h4><p>The request is then forwarded to the web server, where it is processed and the necessary files are retrieved. The web server sends the requested files back to the load balancer, which then sends them on to the client (your computer).</p><p>If the website requires data from a database, the request is forwarded to an application server, which retrieves the necessary data from the database and sends it back to the web server. The web server then includes this data in the response that is sent back to the client.</p><p>Finally, the browser on your computer receives the response and displays the Google homepage on your screen. All of these steps happen in a matter of milliseconds, allowing you to access the website almost instantly.</p><p>In conclusion, when you type<strong> <em>google.com</em></strong> into your web browser, a series of events occur behind the scenes to bring the website to your screen. These include a DNS request to resolve the domain name to an IP address, a TCP connection to the server, firewall security checks, an SSL-encrypted connection, load balancing to distribute traffic, and possibly an application server and database to retrieve and process data. All of these steps work together to bring you the website you requested.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe41e4427b92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create Your Own Shared Hosting Using Docker Containers & AWS]]></title>
            <link>https://aws.plainenglish.io/how-to-create-your-own-shared-hosting-using-docker-containers-it-is-super-easy-fun-ea0960b3d4ea?source=rss-16a2a036380b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea0960b3d4ea</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Mohamed Reda]]></dc:creator>
            <pubDate>Mon, 23 May 2022 14:26:31 GMT</pubDate>
            <atom:updated>2022-05-24T07:55:20.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLaF-buhVOQqeJblxigiEg.png" /><figcaption>Aws docker shared hosting</figcaption></figure><p>Docker is one of the greatest tools available for software developers to test, run and deploy their products it’s like giving your server the <strong>“Infinity gauntlet”</strong>, and in this article, you will learn how to create your own shared hosting which will allow you to create new docker containers as shared servers in milliseconds.</p><p>These servers can have their own os, own ports, and ssh access, and are fully separated from the host server.</p><p>That means, What happens in the docker container stays in the docker container.</p><p>First of all, we need a server and I know: Most people do this kind of tutorial locally, NOT ME.</p><p>We are going to build this on a live server so you can have your own shared hosting business up and running in a matter of minutes or hours it depends <strong><em>LOL</em></strong>.</p><p>To get a server for simplicity reasons I’ll be using AWS Lightsail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Maj__nZ0turLJDmB6mZ_kA.png" /><figcaption>AWS Lightsail</figcaption></figure><p>Now head to <a href="https://lightsail.aws.amazon.com/ls/webapp/home">AWS LightSail</a> and either log in if you already have an AWS account or create a new one.</p><p><em>Congratulations you just became an AWS Cloud Developer!</em></p><p><strong>log-in to your AWS Lightsail dashboard and click on Create Instance.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jO-rt1gQcOixvctno91-g.jpeg" /><figcaption>AWS Lightsail dashboard</figcaption></figure><p><strong>After that select where you want the server location to be </strong>(Here you can pick the nearest one to you or where you want to offer your services)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*VIgQWtemGNTbhNRiiyyieA.png" /><figcaption>AWS Lightsail regions</figcaption></figure><p><strong>Select Linux/Unix as a platform</strong></p><p><strong>Switch to OS Only and choose your favorite Linux distro </strong>(In this tutorial I’ll go with the latest Ubuntu release available which is Ubuntu 20.04 LTS)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*83IBbDC06Nm7kXTVGzoD4Q.png" /><figcaption>AWS Lightsail supported Os</figcaption></figure><p>Next, choose your favorite plan, I’ll go with the cheapest because I’ll probably delete the server after this tutorial <strong><em>LOL</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*y8rrsWzzItZjNeQ8x87_FQ.png" /><figcaption>AWS Lightsail pricing</figcaption></figure><p>Give your machine a name and hit “Create instance”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*YqaPJbf8BlKi_xq49A61Ug.png" /><figcaption>AWS Lightsail dashboard</figcaption></figure><p><em>Congratulations you have your own server running on the cloud!</em></p><h3>Now the fun part begins.</h3><p>After creating the instance your home dashboard should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppo5rjlBLCoN9aFBPWtAWA.png" /><figcaption>AWS Lightsail Dashboard</figcaption></figure><p>As you can see the instance is still in “<strong>pending mode</strong>” which means that you can not access it yet. just wait a little bit and it will switch to <strong>running mode</strong>.</p><p>To access the instant, you can either use your favorite terminal by going to:</p><p><strong>Top bar &gt; Account &gt;Account &gt; </strong><a href="https://lightsail.aws.amazon.com/ls/webapp/account/keys"><strong>SSH Keys</strong></a></p><p>Download the default key of the instance you just created (If you can’t find it just click Create key pair under Default Keys)</p><p>Or click on the built-in shell terminal for easy access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*rW457aTAGW8e7RNvP2TMyw.png" /><figcaption>AWS Lightsail instance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOFdF6cEnsD0hX_FH7zl3Q.png" /><figcaption>AWS built-in shell terminal</figcaption></figure><h3>Installing Docker</h3><p>Before installing docker we need to update our server by running.</p><p>sudo apt update</p><h4>install the packages that will let apt install packages over HTTPS.</h4><pre>sudo apt install apt-transport-https ca-certificates curl software-properties-common</pre><h4>Add the docker’s GPG key to your distro</h4><pre>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vnWd-Mu_P9MHt_HZVa_7NA.png" /></figure><h4>Add docker repository</h4><pre>sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiMPJ3_vOdR7nxSlzEdIpA.png" /></figure><h4>Update system again</h4><p>After adding the docker repository to your distro update the system again</p><pre>sudo apt-get update</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*5mNzWDd_O6RV3jCa56ZTnw.png" /></figure><h3>Install the latest version of docker</h3><p>Install the latest docker version using the command below.</p><pre>sudo apt-get install docker-ce docker-ce-cli containerd.io</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5RdFkq0VMwW8RaRjz6meg.png" /></figure><p>Type <strong>“Y”</strong> and hit <strong>“ENTER”</strong>.</p><p>Congratulations again your server now has SUPERPOWERS!</p><h3>Creating our first Docker container</h3><p>because our installation is new we currently don’t have any docker images on our server, you can check that by running:</p><pre>sudo docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*BClF4U5gLqun76dRxvo5aQ.png" /></figure><h4>Docker image</h4><p>A Docker image is a template that contains instructions for creating a container that can run a specific APP/OS on the Docker platform.</p><h4>Pulling a Docker image</h4><p>pulling a docker image is downloading an image to our server so we can use it to create a container. In our case, I’ll be pulling the latest version of Ubuntu to create multiple Ubuntu virtual machines on our server by running the following command.</p><pre>sudo docker pull ubuntu:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*ruOLpKgUs1JOq9NmBxe7XA.png" /></figure><p>Now if we run sudo docker images we will get the one that we just pulled</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*RBM7GMVCEHlekX0OsUA3sw.png" /></figure><h4>Create a container</h4><p>to create a container we are going to use the <a href="https://docs.docker.com/engine/reference/run/">run</a> command</p><pre>sudo docker run -it -d --name ubuntuContainer -p 2200:22 ubuntu:latest</pre><ul><li><strong>run — </strong>This option will create the container.</li><li><strong>-it — </strong>Allows you to <strong>run a container in interactive mode</strong>. This means you can execute commands inside the container while it is still running.</li><li><strong>-d —</strong> It enables debug mode. In case of an error, it will output all the information related to it.</li><li><strong>- -name —</strong> The name of the container.</li><li><strong>ubuntuContainer — </strong>the name that we gave to our container</li><li><strong>-p 2200:22 —</strong> The -p tag binds the host 2200 port with the container 22 port.</li><li><strong>ubuntu:latest —</strong> the name and the version of the image that we just pulled</li></ul><p><strong>NOTE:</strong> Once a container is created you can not edit which ports are open to open multiple ports just add them separately as shown below.</p><pre>****Do not execute this command****<br>sudo docker run -it -d --name ubuntuContainer -p 2200:22 -p 8080:80 ubuntu:latest<br>****Do not execute this command****</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RtkM-jk1GXBn6qnIYN-Kqw.png" /></figure><p><strong>What we just did</strong> is create a container that is running the latest version of Ubuntu and maps its ssh port (22) to the host server&#39;s 2200 port.</p><p>We can list all running containers using the below command:</p><pre>sudo docker container ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oi86LpFtinEjLVfFeleUcQ.png" /></figure><p><em>Note: Save the container ID because we will be using it in the next command</em></p><h3>Accessing our docker container</h3><p>Our main goal is to be able to access our container from a local terminal and to achieve that we need to set up some stuff inside the container so for now, we will be using the exec command to access our container from our server’s terminal.</p><pre>sudo docker exec -it 8656eaa486a0 /bin/bash</pre><p><em>Note: Instead of using our container ID we can use the name that we gave it when creating the container.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*fMbvONHccvgKl-OdKDZzJg.png" /></figure><p><em>We are in!</em></p><p>As you can see the user name has changed from ubuntu@&lt;IP&gt; to root@&lt;CONTAINER ID&gt;</p><h3>Setup SSH to access our docker container</h3><p>First, let&#39;s update our container by running</p><pre>apt update</pre><h4>Install SSH Server</h4><p>To gain access to our server over ssh we need to install OpenSSH server which is a secure connectivity tool for remote login with the SSH protocol</p><p>To install it just run the following command:</p><pre>apt install openssh-server</pre><p>It will ask you If you want to continue type <strong>‘Y’ </strong>and hit <strong>‘ENTER’</strong></p><p>After installation you can check the status of the ssh service by typing:</p><pre>service --status-all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*jAl-M_bG-0OWbwQVIQOryQ.png" /></figure><p>As you can see in this case our ssh service is not running yet.</p><h4>Updating the root password</h4><p>before we start the ssh service we need to set up our root password to be able to access our server from our local terminal.</p><pre>passwd root</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*se8tt5EX9-_McgzvpOkzCA.png" /></figure><h4>Edit the SSH server config file</h4><p>to do so I’ll install nano to be able to edit the text files.</p><pre>apt install nano</pre><p>after the installation is done we need to edit the ‘sshd_config file’.</p><pre>nano /etc/ssh/sshd_config</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*z89haB1ZZQN9Hnq3QnE3WA.png" /></figure><p>Using the arrow key to navigate the file add the following line</p><pre>PermitRootLogin Yes</pre><p>Under</p><p><strong><em>#PermitRootLogin prohibit-password</em></strong></p><p>Then press <strong>Ctrl+O</strong> to overwrite and <strong>Ctrl+X</strong> to exit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*6_DGZQ-D54rYUN_7aiJX6Q.png" /></figure><h4>Starting SSH</h4><p>To start the ssh server just type:</p><pre>service ssh start</pre><p>Now if we check the status of the ssh service using the command</p><pre>service — status-all</pre><p>We will see that the ssh with the plus sign which means that it is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*Ov_x_7n9nWGDdyY3LR2VeA.png" /></figure><p>now just type <strong>exit</strong> to go back to our host shell.</p><p><em>Congratulations if you reached this step, you have done quite a bit of work. Don’t worry we are near the finish line just one tiny step left to do.</em></p><h3>AWS firewall</h3><p>At this point, our server is running perfectly. the only thing we need to do is to set up our firewall rule.</p><p>by default when you create a new instance the only ports that can receive traffic are 80 and 22.</p><p>since we mapped our container port 22 to our host 2200 we need to allow that traffic to go through.</p><p>To do so, Go to Lightsail Dashboard and click on the container name, select Networking and scroll down to the IPv4 Firewall section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*2V6lRlUhFgvC0PvmUPSIVg.png" /></figure><p>Click on <strong>“Add rule”</strong> and enter the details below.</p><ul><li><strong>Application —</strong> Costume</li><li><strong>Protocol —</strong> TCP</li><li><strong>Port or range —</strong> 2200</li></ul><p>Then click on <strong>“Create”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*ZfxRaB8di-jJWEb3mhkl9g.png" /></figure><p><em>You Did It!</em></p><h3>Access docker container through SSH remotely</h3><p>Now, after everything is set up go to your favorite terminal and type:</p><pre>ssh root@&lt;Server PUBLIC IP&gt; -o 2200</pre><p>In my case, it will look like this</p><pre>ssh root@44.201.119.244 -p 2200</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2-FXxWUgTpnPHMrrvB_sw.png" /></figure><p>Type ‘YES’ and hit “ENTER”.</p><p>Yeah I know “theSmartFridge”, One day I’ll show you how you can run a terminal on your smart fridge LOL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nu1cexjme_EzyAnPLJZcvQ.png" /></figure><p>Enter the root password that we set up early.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SerW6cBlKfhDoXCWZs43-w.png" /></figure><blockquote>Voila, we are in !</blockquote><p><strong>If you made it here you are AWESOME.</strong></p><p>You just made a container running Ubuntu on a VPS running Ubuntu on the Cloud.</p><p><em>I hope you had a great time doing this. With this sort of setup, you can host multiple sites on one server or put all your projects on one server running multiple containers. Also, please don’t hesitate to follow me on </em><a href="https://twitter.com/RedaCodes"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/in/reda-med/"><strong><em>LinkedIn</em></strong></a><em> if you want to know more cool stuff like this.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea0960b3d4ea" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/how-to-create-your-own-shared-hosting-using-docker-containers-it-is-super-easy-fun-ea0960b3d4ea">How to Create Your Own Shared Hosting Using Docker Containers &amp; AWS</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Google Spreadsheets as a Database (Free blog hosting included)]]></title>
            <link>https://javascript.plainenglish.io/how-to-use-google-spreadsheets-as-a-database-free-blog-hosting-included-5f439909d185?source=rss-16a2a036380b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f439909d185</guid>
            <category><![CDATA[blog-hosting]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mohamed Reda]]></dc:creator>
            <pubDate>Tue, 12 Apr 2022 14:28:23 GMT</pubDate>
            <atom:updated>2022-04-14T01:20:56.850Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Use Google Spreadsheets as a Database (Free Blog Hosting Included)</h3><h4>Thanks to Papa Parse &amp; GitHub you can host the cheapest simple static blog with a database completely for free.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ADP3i7PckNGql_c3" /><figcaption>Photo by <a href="https://unsplash.com/@ilyapavlov?utm_source=medium&amp;utm_medium=referral">Ilya Pavlov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We all have that one friend who has their own tiny super niched blog but most of the time that blog is either down or super slow.</p><p>The problem here is that most of these people know little to nothing about managing a website and they often ask us for advice, which most of the time will be “go with WordPress”.</p><p>But sometimes even WordPress can be a pain to manage due to its size, cost and support if you want to have a solid blog.</p><p>To solve this issue I came up with the cheapest, easiest plan to host a simple static blog with a database completely for free (Excluding the cost of registering a domain which can be as low as 0.99$ for your first year).</p><p>Now let’s create our new blog, I’ll call it <a href="https://reda-codes.github.io/TheCatsBlog/">The Cats Blog</a> because why not.</p><p>For the blog template I’ll be using React to keep it simple I’ll create a single component app that manages everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*VGxmNDrkrup6Qey9wLVltA.png" /><figcaption>React app directory layout</figcaption></figure><p>For the database go to <a href="https://docs.google.com/spreadsheets">google spreadsheets</a> and create a table with all the data that you want to import.</p><p>In my case, I created a dummy table that contains Id, Title, Body, and Image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bMxm6IhOxsSk5k9JenYjw.png" /><figcaption>Google spreadsheets data table</figcaption></figure><h3>Importing the data to our website</h3><p>To import the data we will be using a tool called <a href="https://www.papaparse.com/">Papa Parse</a>.</p><p>On your project folder terminal run:</p><pre>npm i papaparse</pre><p>Voila! You have the tool let&#39;s get us some data!</p><pre>const Papa = require(“papaparse”);</pre><pre>const filePrasing = () =&gt; new Promise((resolve)=&gt; {</pre><pre>  Papa.parse(“<strong>YOUR GOOGLE SPREADSHEETS LINK</strong>&quot;, {</pre><pre>   download: true,</pre><pre>   header: true,</pre><pre>   newline: “”,</pre><pre>   complete: function(results, file) {resolve(results.data);}<br>  })<br>})</pre><pre>const getData = async() =&gt; {</pre><pre>const data = await filePrasing();</pre><pre>return data</pre><pre>}</pre><p><strong>Note: In order for Papa Parse to parse your sheet it must be publicly shared as a CSV.</strong></p><p>Now after calling getdata() Papa Parse will get the data from our spreadsheet and returns a promise with all our Data inside one single object.</p><pre>[<br> {<br>   “ID”: “1”,<br>   “title”: “ARTICLE TITLE”,<br>   “body”: “&lt;p&gt;ARTICLE BODY IN HTML&lt;/p&gt;”,<br>   “image”: “<a href="https://placekitten.com/400/500">I</a>MAGE LINK&quot;<br> },<br> {<br>   “ID”: “2”,<br>   “title”: “ARTICLE TITLE”,<br>   “body”: “&lt;p&gt;ARTICLE BODY IN HTML&lt;/p&gt;”,<br>   “image”: “<a href="https://placekitten.com/800/600">I</a>MAGE LINK”<br> }<br>]</pre><p>To do this using react I’ll be using the react hook useState to manage our state and useEffect to update the state when the website renders.</p><pre>/* our data variable */</pre><pre>const [data, setData] = useState([])</pre><pre>useEffect(() =&gt; {</pre><pre>  getData().then((res)=&gt; setData([…res]))</pre><pre>}, []);</pre><pre>/* our data variable */</pre><h3>Blog Layout</h3><p>For the blog layout, our component maps over our state and displays the data on the front end. Also to keep it simple, when the user clicks on an article it’ll be shown on a popup that contains the article’s body due to react being a Single Page Application Framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pOiBzeynNKqmofuR29qOtw.png" /><figcaption>blog layout code</figcaption></figure><p><strong>Note: To get All the code above please go to </strong><a href="https://github.com/Reda-codes/TheCatsBlog"><strong>the project repository on GitHub</strong></a><strong>.</strong></p><h3>The end Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyw2yH10-oXstvKNWsi_hQ.png" /></figure><p>Finally, our <a href="https://reda-codes.github.io/TheCatsBlog/">blog</a> is done and functional the only thing left is to host it.</p><h3>Free Blog hosting</h3><p>Due to our blog being a static web page that fetches data from our Google Spreadsheets on every load we can host it on <a href="https://reda-codes.github.io/TheCatsBlog/">GitHub pages</a> for free and in case you want to have a custom domain for your blog, GitHub allows that for free.</p><p>This project was just a demonstration of how you can use Google Spreadsheets as a database and not a react tutorial, you can build a more complex blog if you use other frameworks that require a server.</p><p>To get all the code for this project head to <a href="https://github.com/Reda-codes/TheCatsBlog"><strong>the project repository on GitHub</strong></a><strong>.</strong></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our</em><strong><em> </em></strong><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our</em><strong><em> </em></strong><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f439909d185" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-use-google-spreadsheets-as-a-database-free-blog-hosting-included-5f439909d185">How to use Google Spreadsheets as a Database (Free blog hosting included)</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>