<?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 Atia Z on Medium]]></title>
        <description><![CDATA[Stories by Atia Z on Medium]]></description>
        <link>https://medium.com/@atiazulfiqar?source=rss-150b334d6b04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*roPhZTDqY9p9iifl6JiXDw.png</url>
            <title>Stories by Atia Z on Medium</title>
            <link>https://medium.com/@atiazulfiqar?source=rss-150b334d6b04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:53:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atiazulfiqar/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 build Chat App using React Server?]]></title>
            <link>https://medium.com/@atiazulfiqar/how-to-build-chat-app-using-react-server-9709cb43fc1?source=rss-150b334d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/9709cb43fc1</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Atia Z]]></dc:creator>
            <pubDate>Sun, 11 Jun 2023 15:22:27 GMT</pubDate>
            <atom:updated>2023-06-11T15:22:27.028Z</atom:updated>
            <content:encoded><![CDATA[<p>Tutorial for building scalable apps using React Server</p><blockquote>In this tutorial, you will gain a comprehensive understanding of React Server <a href="https://state-less.cloud/">https://state-less.cloud/</a>, what problem they solve &amp; a example use case of Chat App.</blockquote><h3>What is React Server?</h3><p>React Server is a great tool for building scalable, modular backends. With React Server, you can create reusable server-side components that can be used to build any type of backend application. These components can be consumed using GraphQL APIs, which makes it easy to build real-time applications.</p><h3>Why do we need it?</h3><p>We need React Server to improve React applications&#39; performance and React Server is a powerful full-stack framework that includes both server-side and client-side libraries.</p><p>It allows developers to use the familiar syntax of React to build their backend code as components, making it easy to transfer any server-side state to the client as TSX props.</p><p>This intuitive approach makes it a fun and efficient way to rapidly prototype sophisticated services with minimal effort.</p><p>React Server also offers several key benefits, including a</p><ol><li>Component-driven architecture that promotes clean and scalable code.</li><li>Server-side rendering capabilities that can improve performance &amp; SEO.</li><li>Real-time updates for an enhanced user experience, and scalability to handle large numbers of users.</li></ol><p>Additionally, React Server is easy to use, even for developers who are new to React, making it a simple yet powerful solution for web applications</p><p>We’ll see how React Server saves time below in the code example</p><blockquote>Let’s get to work now</blockquote><p>We’ll be building a backend using React Server, &amp; a frontend using React Js. Our primary focus is on the backend that’s why we’ll keep frontend simple</p><h3>Pre Requisites</h3><ol><li>Node installed (version 16 or higher)</li><li>Npm installed (version 8 or higher)</li><li>Yarn setup</li><li>Basic Knowledge of React JS &amp; environment setup.</li></ol><h3>Features</h3><ol><li>Add Room</li><li>User List</li><li>Send Message</li></ol><h3>Steps</h3><ol><li>Setting up React Server app</li><li>Setup Client app</li><li>Instantiate a GraphQl client</li><li>Writing backend code</li><li>Write Frontend code</li><li>Running App</li><li>Complete code link</li></ol><h3>Setting up React Server app</h3><p>First of all, we’ll clone a starter app for React Server</p><pre>git clone https://github.com/state-less/clean-starter.git chat-app-backend</pre><p>then change the directory to chat-app-backend</p><pre>cd chat-app-backend</pre><p>Remove the origin of github &amp; install dependencies.</p><pre>git remote remove origin<br>yarn install</pre><p>That&#39;s it, now we can start our server using the following command</p><pre><br>yarn start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yao7-a-4JeuSGE1ItuyEiA.png" /></figure><p>Now we can listen to port <a href="http://localhost:4000/">http://localhost:4000/</a></p><p>Stop the server &amp; move to Client App setup</p><h3>Setup Client app</h3><pre>yarn create vite vite-chat-app</pre><pre>cd vite-chat-app<br>npm install<br>yarn add @mui/material @mui/icons-material<br>yarn add @emotion/react @emotion/styled<br>yarn add @apollo/client @state-less/react-client<br>yarn dev<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IWNURZ8v2sx8Sg7Q-Ki4uA.png" /></figure><h3>Instantiate a GraphQl client</h3><p>We need a GraphQL client to connect our client with the backend server</p><p>Vite JS already gives us a file for the GraphQL client for connectivity.</p><p>Open the frontend app and go to src&gt;lib&gt;client.ts to see graphql client code</p><pre>import { ApolloClient, InMemoryCache, split, HttpLink } from &quot;@apollo/client&quot;;<br>import { WebSocketLink } from &quot;@apollo/client/link/ws&quot;;<br>import { getMainDefinition } from &quot;@apollo/client/utilities&quot;;<br><br>// Create an HTTP link<br>const localHttp = new HttpLink({<br>  uri: &quot;http://localhost:4000/graphql&quot;,<br>});<br><br>// Create a WebSocket link<br>const localWs = new WebSocketLink({<br>  uri: `ws://localhost:4000/graphql`,<br>  options: {<br>    reconnect: true,<br>  },<br>});<br><br>// Use the split function to direct traffic between the two links<br>const local = split(<br>  ({ query }) =&gt; {<br>    const definition = getMainDefinition(query);<br>    return (<br>      definition.kind === &quot;OperationDefinition&quot; &amp;&amp;<br>      definition.operation === &quot;subscription&quot;<br>    );<br>  },<br>  localWs,<br>  localHttp<br>);<br><br>// Create the Apollo Client instance<br>export const localClient = new ApolloClient({<br>  link: local,<br>  cache: new InMemoryCache(),<br>});<br><br>export default localClient;</pre><h3>Building the Backend application</h3><p>Let’s see our backend app, We already have everything we need for the chat app in our clean starter code</p><p>Open our chat-app-backend, then open file <em>chat-app-backend/src/components/ChatRoom.tsx</em></p><pre>import {<br>    ClientContext,<br>    Initiator,<br>    RenderOptions,<br>    Scopes,<br>    authenticate,<br>    useClientEffect,<br>    useState,<br>} from &#39;@state-less/react-server&#39;;<br>import { v4 } from &#39;uuid&#39;;<br>import { ServerSideProps } from &#39;./ServerSideProps&#39;;<br>import { JWT_SECRET } from &#39;../config&#39;;<br><br>export const Room = (<br>    props,<br>    { key, context, initiator, clientProps }: RenderOptions &amp; { key: string }<br>) =&gt; {<br>    const [messages, setMessages] = useState([], {<br>        key: `messages-${key}`,<br>        scope: Scopes.Global,<br>    });<br>    const [clients, setClients] = useState([], {<br>        key: `clients-${key}`,<br>        scope: Scopes.Global,<br>    });<br><br>    useClientEffect(() =&gt; {<br>        let user = null;<br>        try {<br>            user = authenticate((context as ClientContext).headers, JWT_SECRET);<br>        } catch (e) {}<br>        const client = {<br>            user,<br>            id: (context as ClientContext).headers[&#39;x-unique-id&#39;],<br>        };<br>        console.log(&#39;Initiator&#39;, initiator);<br>        if (initiator !== Initiator.Mount)<br>            return () =&gt; {<br>                console.log(<br>                    &#39;!!! Unmounting client&#39;,<br>                    client.id,<br>                    clients.filter((c) =&gt; c.id !== client.id)<br>                );<br>                setClients(clients.filter((c) =&gt; c.id !== client.id));<br>            };<br><br>        if (!clients.find((c) =&gt; c.id === client.id))<br>            setImmediate(setClients([...clients, client]));<br><br>        return () =&gt; {<br>            console.log(<br>                &#39;!!! Unmounting client&#39;,<br>                client.id,<br>                clients.filter((c) =&gt; c.id !== client.id)<br>            );<br>            setClients(clients.filter((c) =&gt; c.id !== client.id));<br>        };<br>    });<br><br>    const sendMessage = (message) =&gt; {<br>        if (typeof message !== &#39;string&#39;) {<br>            throw new Error(&#39;Invalid message&#39;);<br>        }<br>        if (message.length &gt; 100) {<br>            throw new Error(&#39;Message too long&#39;);<br>        }<br>        let user = null;<br>        try {<br>            user = authenticate((context as ClientContext).headers, JWT_SECRET);<br>        } catch (e) {}<br>        const client = {<br>            user,<br>            id: (context as ClientContext).headers[&#39;x-unique-id&#39;],<br>        };<br>        const messageObj = {<br>            author: client,<br>            message,<br>            timestamp: +new Date(),<br>        };<br>        setMessages([...messages, messageObj]);<br>    };<br>    console.log(&#39;Client Props&#39;, clientProps);<br>    return (<br>        &lt;ServerSideProps<br>            key={`${key}-props`}<br>            total={messages.length}<br>            messages={messages.slice((clientProps?.num || 30) * -1)}<br>            clients={clients}<br>            sendMessage={sendMessage}<br>        /&gt;<br>    );<br>};<br><br>export const ChatApp = (props, { key, context }) =&gt; {<br>    const [rooms, setRooms] = useState([], {<br>        key: &#39;rooms&#39;,<br>        scope: Scopes.Global,<br>    });<br><br>    const addRoom = () =&gt; {<br>        let user = null;<br>        try {<br>            user = authenticate((context as ClientContext).headers, JWT_SECRET);<br>        } catch (e) {}<br>        const client = {<br>            user,<br>            id: (context as ClientContext).headers[&#39;x-unique-id&#39;],<br>        };<br><br>        const room = {<br>            id: v4(),<br>            owner: client,<br>        };<br><br>        setRooms([...rooms, room]);<br>    };<br><br>    return (<br>        &lt;ServerSideProps key={`${key}-props`} addRoom={addRoom}&gt;<br>            &lt;Room key=&quot;room-global&quot; /&gt;<br>            {rooms.map((room) =&gt; {<br>                return &lt;Room key={room.id} /&gt;;<br>            })}<br>        &lt;/ServerSideProps&gt;<br>    );<br>};</pre><p>This is all we need for a basic chat app which includes Add Room &amp; Send Message functions</p><p>Inside the component, there are two states defined using the useState hook:</p><ul><li>messages state manages an array of messages using the provided key and with a scope set to Scopes.Global.</li><li>clients state manages an array of connected clients using the provided key and with a scope set to Scopes.Global.</li></ul><p>The useClientEffect hook is used to run an effect when the component is mounted or updated on the client side.</p><ul><li>It checks if the initiator is not, indicating that the client is being unmounted.</li><li>If the client is being unmounted, it removes the client from the clients state.</li><li>If the client is being mounted and is not found in the clients state, it adds the client to the clients state.</li></ul><p>The sendMessage function is defined to handle sending messages.</p><ul><li>It checks the validity of the message and the length of the message.</li><li>It authenticates the user based on the provided headers and JWT_SECRET.</li><li>It creates a message object with the author, message, and timestamp, and adds it to the messages state.</li></ul><p>The addRoom function is defined to add a new room to the rooms state.</p><ul><li>It authenticates the user based on the provided headers and JWT_SECRET.</li><li>It creates a room object with a unique identifier and the owner, and adds it to the rooms state.</li></ul><p>Start server using</p><pre>yarn start</pre><h4>Now Let’s set up our frontend app to integrate our backend app with it.</h4><p>Open our frontend app which we created above called vite-chat-app</p><p>create a components folder inside src, then create a file called ChatApp.tsx</p><p>Add the following code to it.</p><pre>import {<br>    Card,<br>    CardContent,<br>    TextField,<br>    CardActions,<br>    Button,<br>    Grid,<br>    ListItem,<br>    ListItemText,<br>    Box,<br>    Avatar,<br>    Chip,<br>    Typography,<br>  } from &#39;@mui/material&#39;;<br>  import { useComponent } from &#39;@state-less/react-client&#39;;<br>  import { useEffect, useRef, useState } from &#39;react&#39;;<br><br>  export const ChatApp = () =&gt; {<br>    const [items, setItems] = useState(10);<br>    const [room, { loading }] = useComponent(&#39;room-global&#39;, {<br>      props: {<br>        num: items,<br>      },<br>    });<br>    const { messages = [], sendMessage } = room?.props || {};<br>    const [text, setText] = useState(&#39;&#39;);<br>    const ref = useRef&lt;HTMLDivElement&gt;(null);<br><br>    useEffect(() =&gt; {<br>      setTimeout(() =&gt; {<br>        ref.current?.scrollTo({<br>          top: ref.current?.scrollHeight,<br>        });<br>      }, 100);<br>    }, [loading]);<br><br>    return (<br>      &lt;Card sx={{width: &#39;100%&#39;}}&gt;<br>        &lt;CardContent&gt;<br>          &lt;Grid container spacing={1}&gt;<br>            &lt;Grid item xs={9}&gt;<br>              &lt;Box sx={{ display: &#39;flex&#39;, width: &#39;100%&#39; }}&gt;<br>                &lt;Button<br>                  disabled={items &gt;= room?.props?.total}<br>                  onClick={() =&gt; setItems(items + 10)}<br>                  sx={{ mx: &#39;auto&#39; }}<br>                &gt;<br>                  Load More {items}<br>                &lt;/Button&gt;<br>              &lt;/Box&gt;<br>  <br>              &lt;Box<br>                sx={{<br>                  height: &#39;500px&#39;,<br>                  overflowY: &#39;scroll&#39;,<br>                }}<br>                ref={ref}<br>              &gt;<br>                &lt;Box<br>                  sx={{<br>                    display: &#39;flex&#39;,<br>                    flexDirection: &#39;column&#39;,<br>                    gap: 1,<br>                  }}<br>                &gt;<br>                  {messages.map((message) =&gt; {<br>                    return (<br>                      &lt;Card&gt;<br>                        &lt;CardContent sx={{ py: &#39;0px !important&#39; }}&gt;<br>                          &lt;Typography&gt;{message?.message}&lt;/Typography&gt;<br>                        &lt;/CardContent&gt;<br>                        &lt;CardActions&gt;<br>                          {new Date(message?.timestamp).toLocaleString()}<br>                          &lt;Chip<br>                            sx={{ ml: &#39;auto&#39; }}<br>                            avatar={<br>                              &lt;Avatar<br>                                sx={{ width: 24, height: 24 }}<br>                                src={<br>                                  message?.author?.user?.strategies?.google<br>                                    ?.decoded?.picture<br>                                }<br>                              /&gt;<br>                            }<br>                            label={<br>                              message?.author?.user?.strategies?.google?.decoded<br>                                ?.name || message?.author?.id<br>                            }<br>                          &gt;&lt;/Chip&gt;<br>                        &lt;/CardActions&gt;<br>                      &lt;/Card&gt;<br>                    );<br>                  })}<br>                &lt;/Box&gt;<br>              &lt;/Box&gt;<br>  <br>              &lt;TextField<br>                fullWidth<br>                rows={3}<br>                multiline<br>                value={text}<br>                onChange={(e) =&gt; setText(e.target.value)}<br>                sx={{ mt: 1 }}<br>              &gt;&lt;/TextField&gt;<br>            &lt;/Grid&gt;<br>            &lt;Grid item xs={3}&gt;<br>              {room?.props?.clients?.map?.((client) =&gt; {<br>                return (<br>                  &lt;ListItem&gt;<br>                    &lt;ListItemText<br>                      primary={<br>                        client?.user?.strategies?.google?.decoded?.name ||<br>                        client?.id<br>                      }<br>                    &gt;&lt;/ListItemText&gt;<br>                  &lt;/ListItem&gt;<br>                );<br>              })}<br>            &lt;/Grid&gt;<br>          &lt;/Grid&gt;<br>        &lt;/CardContent&gt;<br>        &lt;CardActions&gt;<br>          &lt;Button<br>            disabled={text?.length &lt; 3}<br>            onClick={() =&gt; {<br>              sendMessage(text);<br>              setText(&#39;&#39;);<br>            }}<br>          &gt;<br>            Send<br>          &lt;/Button&gt;<br>        &lt;/CardActions&gt;<br>      &lt;/Card&gt;<br>    );<br>  };</pre><h4>Add our component in App.tsx</h4><pre>import localClient from &#39;./lib/client&#39;<br>import { ChatApp } from &#39;./components/ChatApp&#39;<br>import { ApolloProvider } from &#39;@apollo/client&#39;<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;ApolloProvider client={localClient}&gt;<br>        &lt;ChatApp /&gt;<br>      &lt;/ApolloProvider&gt;<br>    &lt;/&gt;<br>  )<br>}<br><br>export default App</pre><p>Remove index.css from main.tsx</p><pre>import React from &#39;react&#39;<br>import ReactDOM from &#39;react-dom/client&#39;<br>import App from &#39;./App.tsx&#39;<br><br>ReactDOM.createRoot(document.getElementById(&#39;root&#39;) as HTMLElement).render(<br>  &lt;React.StrictMode&gt;<br>    &lt;App /&gt;<br>  &lt;/React.StrictMode&gt;,<br>)</pre><p>Now let start our app</p><pre>yarn dev</pre><p>This will start our app <a href="http://127.0.0.1:5174/">http://127.0.0.1:5174/</a> you can see it here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aduccdcc91wjIJzQjwE_KA.png" /></figure><blockquote><em>Did you find it helpful?</em></blockquote><blockquote>If you’re in need of a skilled web or app developer, I’m here to help! Please don’t hesitate to reach out to me via email (codewithatia@gmail.com) if you have any questions or would like to discuss your project further. I look forward to hearing from you!</blockquote><p><em>Subscribe </em><a href="https://medium.com/subscribe/@atiazulfiqar"><strong><em>here</em></strong></a><em> to be on my email list to be notified of my new exciting blogs.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*yXVSC9unHg8vRxosKAa2QQ.png" /></figure><blockquote><em>Follow me on </em><a href="https://www.instagram.com/codewithatia/"><em>Instagram</em></a><em>, </em><a href="https://github.com/AtiaK"><em>GitHub</em></a><em>, </em><a href="https://www.linkedin.com/in/web-developer-mobile-app-developer/"><em>LinkedIn</em></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9709cb43fc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build CRUD API using Node JS, Express JS & MongoDB]]></title>
            <link>https://medium.com/@atiazulfiqar/easily-build-crud-api-using-node-js-mongodb-c16f27ddf8aa?source=rss-150b334d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/c16f27ddf8aa</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[postman]]></category>
            <dc:creator><![CDATA[Atia Z]]></dc:creator>
            <pubDate>Tue, 13 Dec 2022 05:12:57 GMT</pubDate>
            <atom:updated>2023-03-31T11:27:05.379Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s a tutorial for building CRUD APIs (CREATE, READ, UPDATE, DELETE) for absolute beginners with complete code.</p><p>In this tutorial, you will learn to build CRUD APIs (Create, Read, Update, Delete) in Node JS. We’ll create CRUD for a Recipe App.</p><p><strong>Here’re the features of the Recipe App</strong></p><ol><li><strong><em>Create a Recipe</em></strong></li><li><strong><em>List all Recipes</em></strong></li><li><strong><em>Update Recipe</em></strong></li><li><strong><em>Delete a Recipe</em></strong></li></ol><h3>Pre Req</h3><ol><li>Node &amp; Npm installed.</li><li>Basic Knowledge of Node JS &amp; environment setup.</li><li>MongoDB account for storing data.</li><li>Postman for API testing</li></ol><h3>Steps</h3><ol><li>Setting up Node JS app</li><li>Installing dependencies</li><li>Creating Server</li><li>Connecting to Mongo DB</li><li>Creating Recipe Model</li><li>Creating Routes (Create, Read, Update, Delete)</li><li>Testing APIs using Postman</li></ol><h3>Setting up Node JS App</h3><p>Let’s create a folder for our app.</p><pre>mkdir recipe-app</pre><p>Navigate to folder</p><pre>cd recipe-app</pre><p>Initialize Node JS project</p><pre>npm init -y</pre><p>This will create package. json in recipe-app folder.</p><h3>Install Dependencies</h3><pre> npm install mongoose express dotenv cors nodemon</pre><p><strong>express</strong> =&gt; It’s a NodeJS framework which allows to set up middleware to respond to HTTP Requests.</p><p><strong>mongoose =&gt; </strong>Mongoose is a <a href="https://www.mongodb.org/">MongoDB</a> object modeling tool designed to work in an asynchronous environment</p><p><strong>dotenv =&gt;</strong> module that loads environment variables from a .env file</p><p><strong>cors =&gt;</strong> it’s used for enabling cors</p><p><strong>nodemon</strong> =&gt; it is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected.</p><h4><strong>Add nodemon to package.json</strong></h4><pre>{<br>  &quot;name&quot;: &quot;recipe-app&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>    &quot;start&quot;: &quot;nodemon index.js&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;cors&quot;: &quot;^2.8.5&quot;,<br>    &quot;dotenv&quot;: &quot;^16.0.3&quot;,<br>    &quot;express&quot;: &quot;^4.18.2&quot;,<br>    &quot;mongoose&quot;: &quot;^6.8.0&quot;,<br>    &quot;nodemon&quot;: &quot;^2.0.20&quot;<br>  }<br>}</pre><h3>Creating Server</h3><p>We’ll create a root file where we’ll create express server.</p><p>Create index.js file in root file</p><pre>const express = require(&quot;express&quot;);<br><br>const PORT = 3000;<br><br>const app = express();<br><br>app.listen(PORT, async () =&gt; {<br>  console.log(`Server Listeining on ${PORT}`);<br>});</pre><p>This will create server which listens on PORT 3000</p><p>Now run this command to start app</p><pre>npm start</pre><p>This will start our server which is running on port 3000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*luxjiis2aNAdx7JV6Eyu2Q.png" /></figure><h3>Connecting to MongoDB</h3><p><strong>If you don’t have MongoDB, you can set it up by following this </strong><a href="https://mydaytodo.com/setup-mongodb-mongo-shell-compass/#:~:text=How%20to%20setup%20local%20MongoDB%20database%20%28Mac%29%201,%2Fdata%2Fdb%203%20sudo%20chown%20-R%20id%20-un%20%2Fdata%2Fdb"><strong>local</strong></a><strong> or </strong><a href="https://www.mongodb.com/docs/guides/atlas/connection-string/"><strong>cloud</strong></a><strong>.</strong></p><p>Create .env file in your root folder</p><p>Copy your MongoDB connection string from local MongoDB or MongoDB atlas &amp; paste it in .env file</p><pre>MONGO_DB_STRING= paste your mongo string here</pre><p>Now create a file called db.js in root folder, add following code into it.</p><pre>const mongoose = require(&#39;mongoose&#39;);<br>require(&#39;dotenv&#39;).config()<br>module.exports = () =&gt;<br>  new Promise(async (resolve, reject) =&gt; {<br>    try {<br>      // Connect to MongoDB<br>      mongoose.set(&#39;strictQuery&#39;,false);<br>      const URL = process.env.MONGO_DB_STRING<br>      await mongoose.connect(URL);<br><br>      console.log(&#39;MongoDB Connected...&#39;);<br>      <br>      resolve(true);<br>    } catch (error) {<br>      console.log(&#39;MongoDB Connection Error: &#39;, error);<br>      reject(error);<br>    }<br>  });</pre><p>import<strong> db.js </strong>file into<strong> index.js</strong> to connect our app to MongoDB</p><pre>const express = require(&quot;express&quot;);<br>const PORT = 3000;<br>const app = express();<br>const db=require(&#39;./db&#39;);<br><br>db()<br><br>app.listen(PORT, async () =&gt; {<br>  console.log(`server up on port ${PORT}`);<br>});</pre><p>Now check if it works, run <strong>npm start</strong> in your console. This is how it should look</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZGaUSdm5hmKxpID4t-1frQ.png" /></figure><h3>Create Recipe Model</h3><p>We’ll define our recipe collection in our Recipe model. Create a folder model<strong> </strong>in root, inside of it create a file<strong> models/Recipe.js.</strong></p><p>Recipe collection will have following fields</p><ol><li>Name (String)</li><li>Ingredients (Array)</li><li>Cuisine (String)</li><li>timestamp</li></ol><pre>const mongoose = require(&quot;mongoose&quot;);<br><br>const RecipeSchema = new mongoose.Schema({<br>  Name: {<br>    type: String,<br>    required: true,<br>  },<br>  Ingredients: {<br>    type: Array,<br>    required:true<br>  },<br>  Cuisine: {<br>    type: String,<br>    required:true<br>  }<br>},{timestamps:true});<br><br>module.exports = mongoose.model(&quot;recipe&quot;, RecipeSchema);</pre><h3>Creating Routes</h3><p>Create a folder called routes, create a file index.js inside of it. Add following code into it.</p><pre>const express=require(&#39;express&#39;)<br>//import router to create routes<br>const router = express.Router();</pre><p>Express router will let us create HTTP requests for CRUD.</p><p><strong>If you’re not already familiar with HTTP Methods, here’s a little peek into it.</strong></p><ol><li><em>POST (it’s used t</em>o create new data)</li></ol><p><em>2. GET (For retrieving data)</em></p><p><em>3. PUT (it’s used for updating data)</em></p><p><em>4. DELETE (As name applies, it’s used for deleting data)</em></p><h4>Add a Recipe</h4><p>Let’s create a POST route for adding recipe.</p><pre>//add recipe<br>router.post(&#39;/&#39;, function(req, res, next) {<br>    try {<br>        const {Name,Ingredients,Cuisine}=req.body;<br>        const newRecipe=new RecipeModel({Name,Ingredients,Cuisine})<br>        newRecipe.save();<br>    <br>        return res.status(200).send({message:&quot;Data has been added!&quot;,data:newRecipe})<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured!&quot;,error:error.message})<br>    }<br>});</pre><h4>List all Recipes</h4><pre>/* GET recipe listing. */<br>router.get(&#39;/&#39;, function(req, res, next) {<br>    try {<br>        const recipes= RecipeModel.find({});<br>        return res.status(200).send({message:&quot;Data has been added!&quot;,data:recipes})<br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured!&quot;,error:error.message})<br>    }<br>});</pre><h4>Update a Recipe</h4><pre>//update recipe<br>router.put(&#39;/:recipeId&#39;, function(req, res, next) {<br>    try {<br>        const recipeId= req.params.recipeId;<br>        const {Name,Ingredients,Cuisine}=req.body;<br>        RecipeModel.findByIdAndUpdate(recipeId,{Name,Ingredients,Cuisine})<br>    <br>        return res.status(200).send({message:&quot;Recipe has been updated!&quot;})<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured in update!&quot;,error:error.message})<br>    }<br>});</pre><h4>Delete Recipe</h4><pre>//delete recipe<br>router.delete(&#39;/:recipeId&#39;, function(req, res, next) {<br>    try {<br>        const recipeId= req.params.recipeId;<br>        RecipeModel.findByIdAndDelete(recipeId)<br>    <br>        return res.status(200).send({message:&quot;Recipe has been updated!&quot;})<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured in update!&quot;,error:error.message})<br>}});</pre><p>Here’s full routes/index.js file</p><pre>var express = require(&#39;express&#39;);<br>var router = express.Router();<br>//import recipe model<br>const RecipeModel=require(&#39;../models/Recipe&#39;);<br><br>/* GET recipe listing. */<br>router.get(&#39;/&#39;, function(req, res, next) {<br>    try {<br>        const recipes= RecipeModel.find({});<br>        return res.status(200).send({message:&quot;Data has been added!&quot;,data:recipes});<br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured!&quot;,error:error.message});<br>    }<br>});<br><br>//add recipe<br>router.post(&#39;/&#39;, function(req, res, next) {<br>    try {<br>        const {Name,Ingredients,Cuisine}=req.body;<br>        const newRecipe=new RecipeModel({Name,Ingredients,Cuisine});<br>        newRecipe.save();<br>    <br>        return res.status(200).send({message:&quot;Data has been added!&quot;,data:newRecipe});<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured!&quot;,error:error.message});<br>    }<br>});<br>  <br>//delete recipe<br>router.delete(&#39;/:recipeId&#39;, function(req, res, next) {<br>    try {<br>        const recipeId= req.params.recipeId;<br>        RecipeModel.findByIdAndDelete(recipeId);<br>    <br>        return res.status(200).send({message:&quot;Recipe has been updated!&quot;});<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured in update!&quot;,error:error.message});<br>}});<br>  <br>//update recipe<br>router.put(&#39;/:recipeId&#39;, function(req, res, next) {<br>    try {<br>        const recipeId= req.params.recipeId;<br>        const {Name,Ingredients,Cuisine}=req.body;<br>        RecipeModel.findByIdAndUpdate(recipeId,{Name,Ingredients,Cuisine});<br>    <br>        return res.status(200).send({message:&quot;Recipe has been updated!&quot;});<br>    <br>    } catch (error) {<br>        return res.status(400).send({message:&quot;Error Occured in update!&quot;,error:error.message});<br>    }<br>});<br><br>module.exports = router;</pre><p>Now import this in root index.js file</p><pre>const indexRouter=require(&#39;./routes/index&#39;);<br>app.use(&#39;/&#39;, indexRouter);</pre><p>we’ll add middleware to our app which will parse incoming JSON requests and puts the parsed data in req.body</p><pre>app.use(express.json());</pre><p>If we don’t use middleware POST API will throw an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ThmyaQO1YD-p07r5Lb1oA.png" /></figure><p>Here’s complete index.js file</p><pre>const express = require(&quot;express&quot;);<br>const PORT = 3000;<br>const app = express();<br>const db=require(&#39;./db&#39;);<br>db()<br>const cors = require(&quot;cors&quot;);<br>app.use(cors())<br>app.use(express.json());<br>const indexRouter=require(&#39;./routes/index&#39;)<br><br>app.use(&#39;/&#39;, indexRouter);<br><br><br>app.listen(PORT, async () =&gt; {<br>  console.log(`Server Listeining on ${PORT}`);<br>});</pre><h3>Testing APIs</h3><p>We’ll use Postman to test our APIs, <strong>Postman</strong> is an API platform for developers to design, build, test and iterate their APIs.</p><p>Start your app using</p><pre>npm start</pre><p>You can listen to your app here <a href="http://localhost:3000/">http://localhost:3000/</a></p><h4>Create Recipe API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-rRGZ7pnVMK9exMwvmlhw.png" /></figure><h4>List Recipes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwVL5UNu-BrwKIeUmJ-HUg.png" /></figure><h4>Update Recipe</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EWwLxdgtN-eKbCBqBkAJYA.png" /></figure><h4>Delete a recipe</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zqSXiVa2cTzzLzabggCVg.png" /></figure><p>Here’s complete code <a href="https://github.com/AtiaK/recipe-app">https://github.com/AtiaK/recipe-app</a></p><blockquote><em>Did you find it helpful?</em></blockquote><p><em>Let me know if you found this helpful or need any help.</em></p><p><em>Subscribe </em><a href="https://medium.com/subscribe/@atiazulfiqar"><strong><em>here</em></strong></a><em> to be on my email list to be notified for my new exciting blogs.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*GOCVO5V2W4ERJ3q5O9SRtQ.png" /></figure><blockquote><em>Follow me on </em><a href="https://www.instagram.com/codewithatia/"><strong><em>Instagram</em></strong></a><strong><em>, </em></strong><a href="https://github.com/AtiaK"><strong><em>GitHub</em></strong></a><strong>, </strong><a href="https://www.linkedin.com/in/web-developer-mobile-app-developer/"><strong>LinkedIn</strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c16f27ddf8aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to upload image to Cloudinary using Node JS?]]></title>
            <link>https://medium.com/@atiazulfiqar/how-to-upload-image-to-cloudinary-using-node-js-62ea1d688c50?source=rss-150b334d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/62ea1d688c50</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Atia Z]]></dc:creator>
            <pubDate>Sat, 29 Oct 2022 05:18:01 GMT</pubDate>
            <atom:updated>2022-10-29T05:18:01.795Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s tutorial for handling images &amp; uploading it to Cloudinary.</p><p>It’s most common required feature &amp; yet it seems difficult most beginners.</p><p>In this article we’re going to create REST API, which will take image as an input sends it to server to store in Cloudinary, then we’ll take URL to store in DB.</p><h3>Pre Req:</h3><ol><li>Node &amp; Npm installed.</li><li>Basic Knowledge of Node JS &amp; environment setup.</li><li>MongoDB for storing data.</li><li>Cloudinary Account</li><li>Postman for API testing.</li></ol><h3>Steps:</h3><ol><li>Setting up new express project</li><li>Installing Dependencies</li><li>Create .env file</li><li>Mongo Db Connection</li><li>Add Model</li><li>Multer &amp; Cloudinary Configuration</li><li>Creating Controller &amp; Route.</li><li>Testing API</li></ol><h3>Setting up new express project</h3><p>Use<a href="https://expressjs.com/en/starter/generator.html"> express-generator</a> for quick skeleton code.</p><blockquote>npx express-generator upload_image</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZrOyaYSZWG5ogvMyB4bMA.png" /></figure><p>after this then run</p><blockquote>cd upload_image</blockquote><blockquote>npm i</blockquote><blockquote>npm start</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*LsS1jZ6Y0_axpo9O2UER9w.png" /></figure><h3>Installing Dependencies</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*Neyo_zJfjo6xp0sVNQcy1A.png" /><figcaption>Dependencies</figcaption></figure><p><strong>Multer =&gt;</strong> Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files</p><p><strong>Cloudinary =&gt; </strong>allows to quickly and easily integrate application with Cloudinary.</p><p><strong>body-parser </strong>=&gt; Parse incoming request bodies in a middleware before your handlers, available under the req.body property.</p><p><strong>mongoose =&gt; </strong>Mongoose is a <a href="https://www.mongodb.org/">MongoDB</a> object modeling tool designed to work in an asynchronous environment</p><p><strong>dotenv =&gt; m</strong>odule that loads environment variables from a .env file</p><p><strong>nodemon</strong> =&gt; it is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected.</p><h4>Add nodemon into package.json file</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*x0nLwvNca4bfD8TSdC9FVg.png" /><figcaption>package.json</figcaption></figure><h3>Create .env</h3><p>Create .env file in your root folder. We’ll add following variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QewF2v1EN1Y2dpgpNa-a8w.png" /><figcaption>.env</figcaption></figure><h3>Mongo Db Connection</h3><p>Create file db.js in your root folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vIpu4k4VDb_mgTBeGh0imQ.png" /><figcaption>db.js</figcaption></figure><p>import it in app.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nktUsdP4S6DV2Kko8nVQVw.png" /><figcaption>app.js</figcaption></figure><h3>Add Model</h3><p>Create models folder &amp; Image.js file inside of models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h02vwmIAB1PAwZu9bNfI3A.png" /><figcaption>Image.js</figcaption></figure><h3>Cloudinary Config</h3><p>Go to your Cloudinary account, then go to dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pl4fiKfERlYZRoMvKm_qXQ.png" /></figure><p>Copy &amp; Paste these (Cloud Name, API Key, API Secret) into .env file.</p><p>Create Folder config &amp; a file called cloudinaryConfig.js inside of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kA3iY1ygJDl8-3f3Z0ZGIg.png" /><figcaption>CloudinaryConfig.js</figcaption></figure><p>we’ll use this function to upload image to Cloudinary.</p><h3>Add Multer</h3><p>Create public/images folder in your root.</p><p>Create a file multerConfig.js inside config folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KMP-pMn1gZmnMJrNDAVMQw.png" /><figcaption>multerConfig.js</figcaption></figure><p>Here we’re validating image format type, this will check if it matches correct type then it’ll upload image to local folder public/images otherwise it’ll throw error.</p><h3>Create Controller</h3><p>Create folder called <strong>controllers </strong>in root directory.</p><p>Create a file <strong>controllers/ImageController.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQIZD3wymRvRj6EYRao8aQ.png" /><figcaption>ImageController.js</figcaption></figure><h3>Create Route</h3><p>Add route in routes/index.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dL7H5NesVJ9pfaOBYRPiow.png" /><figcaption>index.js</figcaption></figure><p>Import route &amp; Db connection in app.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PypTV447bVYUrQJsUCzoBw.png" /><figcaption>app.js</figcaption></figure><h3>Testing</h3><p>Start your app by running<strong> npm start</strong></p><p><a href="http://localhost:3000/">http://localhost:3000/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v08JuplTYrlTqNl_lGMbzw.png" /></figure><h3>Conclusion</h3><p>We’ve completed an endpoint which receives image in form data, uploads image to Cloudinary &amp; then stores it to DB.</p><p>Here’s complete code <a href="https://github.com/AtiaK/upload_image_cloudinary">AtiaK/upload_image (github.com)</a></p><blockquote><em>Did you find it helpful?</em></blockquote><p><em>Let me know if you found this helpful or need any help.</em></p><p><em>Subscribe </em><a href="https://medium.com/subscribe/@atiazulfiqar"><strong><em>here</em></strong></a><em> to be on my email list to be notified for my new exciting blogs.</em></p><p><em>Follow me on </em><a href="https://www.instagram.com/codewithatia/"><strong><em>instagram</em></strong></a><strong><em>, </em></strong><a href="https://github.com/AtiaK"><strong><em>github</em></strong></a><strong>, </strong><a href="https://www.linkedin.com/in/web-developer-mobile-app-developer/"><strong>linkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62ea1d688c50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to upload image to Server using multer in NodeJS?]]></title>
            <link>https://medium.com/@atiazulfiqar/how-to-upload-image-to-server-using-multer-in-nodejs-d4cc5c8d92b2?source=rss-150b334d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4cc5c8d92b2</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[multer]]></category>
            <dc:creator><![CDATA[Atia Z]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 12:38:42 GMT</pubDate>
            <atom:updated>2022-10-10T11:14:49.271Z</atom:updated>
            <content:encoded><![CDATA[<h3>Here’s tutorial for handling images &amp; uploading it.</h3><p>It’s most common required feature &amp; yet it seems difficult to most beginners.</p><p>In this article we’re going to create REST API, which will take image as an input sends it to server.</p><h3>Pre Req:</h3><ol><li>Node &amp; Npm installed.</li><li>Basic Knowledge of Node JS &amp; environment setup.</li><li>Postman for API testing.</li></ol><h3>Steps:</h3><ol><li>Setting up new express project</li><li>Installing Dependencies</li><li>Multer config</li><li>Creating Route</li><li>Testing API</li></ol><h3>Setting up new express project</h3><p>Use<a href="https://expressjs.com/en/starter/generator.html"> express-generator</a> for quick skeleton code.</p><blockquote>npx express-generator upload_image</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZrOyaYSZWG5ogvMyB4bMA.png" /></figure><p>after this then run</p><blockquote>cd upload_image</blockquote><blockquote>npm i</blockquote><blockquote>npm start</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*LsS1jZ6Y0_axpo9O2UER9w.png" /></figure><h3>Installing Dependencies</h3><p>run this command</p><blockquote>npm i multer nodemon</blockquote><p><strong>Multer =&gt;</strong> Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files</p><p><strong>nodemon</strong> =&gt; it is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected.</p><h4>Add nodemon into package.json file</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vt3h9aPPNo9cxEII-navOw.png" /><figcaption>package.json</figcaption></figure><h3>Add Multer</h3><p>Create a file multerConfig.js inside config folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KMP-pMn1gZmnMJrNDAVMQw.png" /><figcaption>multerConfig.</figcaption></figure><p>Here we’re validating image types, this will check if it matches correct type then it’ll upload image to local folder public/images otherwise it’ll throw an error.</p><h4>Finally let’s Create an Endpoint to receive image</h4><p>Add this in routes/index.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vFRRgMlMXClby2f5TycxpQ.png" /><figcaption>index.js</figcaption></figure><h3>Testing</h3><p>Request POST <a href="http://localhost:3000/postImage">http://localhost:3000/postImage</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k5kFPLMekFjUvwpDC8bzBg.png" /><figcaption>postman</figcaption></figure><p>Here you can see image is saved to server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFor8p_-MbIs2hiqqD6OMw.png" /></figure><h3>Conclusion</h3><p>We’ve completed an endpoint which receives image in form data &amp; stores in public/images folder.</p><p>Here’s complete code <a href="https://github.com/AtiaK/upload_image">AtiaK/upload_image (github.com)</a></p><blockquote>Did you find it helpful?</blockquote><p><em>Let me know if you found this helpful or need any help.</em></p><p><em>Subscribe </em><a href="https://medium.com/subscribe/@atiazulfiqar"><em>here</em></a><em> to be on my email list to be notified for my new exciting blogs.</em></p><p><em>Cheers, See you in next one.</em></p><p><em>Follow me on </em><a href="https://www.instagram.com/codewithatia/"><em>instagram</em></a><em>, </em><a href="https://github.com/AtiaK"><em>github</em></a>, <a href="https://www.linkedin.com/in/web-developer-mobile-app-developer/">linkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4cc5c8d92b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do I recharge myself to avoid burnout as a developer?]]></title>
            <link>https://medium.com/@atiazulfiqar/how-do-i-recharge-myself-to-avoid-burnout-as-a-developer-9bfe6f990c43?source=rss-150b334d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bfe6f990c43</guid>
            <category><![CDATA[software-developer]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[burnout]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Atia Z]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 12:19:28 GMT</pubDate>
            <atom:updated>2022-09-25T12:19:28.490Z</atom:updated>
            <content:encoded><![CDATA[<h4>How often do you feel exhausted while sitting on a chair? 🤔</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tjdB9tuk1DRBl3iJshvrw.jpeg" /><figcaption><a href="https://unsplash.com/photos/Xx4i6wg6HEg">Free Grey Image on Unsplash</a></figcaption></figure><p>Burnout is the leading cause of low productivity &amp; low creativity, without productivity, we can’t code &amp; create awesome stuff.</p><p><em>I used to work a lot even on weekends, not giving myself any breaks or self-care time. This resulted in health issues, which caused low confidence &amp; low productivity, then I realized that I was falling into a hustle culture trap. I had to step out of it so, I did.</em></p><blockquote>It’s okay to do nothing sometimes.</blockquote><h3><strong>Root Causes</strong></h3><blockquote>Working a lot.</blockquote><blockquote>No Rest</blockquote><blockquote>Following Perfectionism culture</blockquote><blockquote>Health doesn’t come first</blockquote><h3>I’ve added a few things to my routine to avoid frequent burnout.</h3><h4>Do Not Code Time</h4><p>Book time for yourself, and block hours in which you don’t work. You can do something you love. Pick a hobby like reading books, playing video games, or sports.</p><p>I usually go out for a walk or play games.</p><h4>Good Sleep</h4><p>Sleep loss is a major contributor to burnout. Less sleep will cause fatigue and ultimately lead to burnout. Our mind and body should reload properly if you do not load it well, it will cause health problems too.<br>Keep track of sleep time and sleep 7 to 8 hours a day.</p><h4>Work Routine</h4><p>Set up your working hours &amp; split in intervals. It will help you to improve your focus &amp; prevent burnout (<a href="https://thenextfind.com/pros-cons-of-pomodoro-technique/">read more</a>). I’m using the Pomodoro technique; it is a technique where you take short breaks in between work intervals.</p><p>“There are six steps in the technique:</p><ol><li>Decide on the task to be done.</li><li>Set the pomodoro timer (traditionally to 25 minutes).</li><li>Work on the task.</li><li>End work when the timer rings and put a checkmark on a piece of paper.</li><li>If you have fewer than four checkmarks, take a short break (3–5 minutes), then go to step 2.<a href="https://en.wikipedia.org/wiki/Pomodoro_Technique#:~:text=The%20original%20technique%20has%20six%20steps%3A%201%20Decide,you%20go%20through%20all%20three%20pomodoros.%20More%20items"> read more</a>”</li></ol><h4>Exercise</h4><p>Get your body moving, Cardio will help you to reduce stress level &amp; exhaustion. My favorite cardio is skipping, I do it regularly. You can add walk, jog, cycling or any other exercise in your routine.</p><h4>Celebrating Small Wins</h4><p>Celebrate that error you resolved, give yourself a small treat like you’ve achieved something. It’ll make you feel good about yourself &amp; help you to reflect on your progress. When you reflect on your achievement, your brain will activate reward center which produces dopamine.</p><h4>Conclusion</h4><p>Burnouts are constant, but you can definitely cope with it, these are the things which are helping me. It’ll definitely benefit you too if you follow it consistently.</p><blockquote>Good Luck!</blockquote><blockquote><em>Thanks for reading! If you enjoyed this article, make sure to leave a👏, if you want me to cover a topic, feel free to let me know in comments below. 👇💬</em></blockquote><blockquote><em>Subscribe </em><a href="https://medium.com/subscribe/@atiazulfiqar"><em>here</em></a><em> 💌 to be on my email list to be notified for my new exciting blogs. 🔔</em></blockquote><blockquote><em>Cheers, See you in next one. 🎉</em></blockquote><blockquote><em>Follow me on i</em><a href="https://www.instagram.com/codewithatia"><em>nstagram</em></a><em> , </em><a href="https://github.com/AtiaK"><em>github</em></a><em>, </em><a href="https://www.linkedin.com/in/web-developer-mobile-app-developer/"><em>linkedIn</em></a><em> &amp; </em><a href="https://medium.com/@atiazulfiqar"><em>medium</em></a><em> 😻</em></blockquote><h3>References</h3><p><a href="https://medium.com/r?url=https%3A%2F%2Fthenextfind.com%2Fpros-cons-of-pomodoro-technique%2F">Redirecting you - Medium</a></p><p><a href="https://en.wikipedia.org/wiki/Pomodoro_Technique#:~:text=The%20original%20technique%20has%20six%20steps:%201%20Decide,you%20go%20through%20all%20three%20pomodoros.%20More%20items">Pomodoro Technique — Wikipedia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bfe6f990c43" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>