<?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 Hamzah on Medium]]></title>
        <description><![CDATA[Stories by Hamzah on Medium]]></description>
        <link>https://medium.com/@hbosnjo?source=rss-cf9e3e90262d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DTNGW7xnrZZUq7gu</url>
            <title>Stories by Hamzah on Medium</title>
            <link>https://medium.com/@hbosnjo?source=rss-cf9e3e90262d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 07:13:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hbosnjo/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[App Router vs Pages Router in Next.js]]></title>
            <link>https://medium.com/@hbosnjo/app-router-vs-pages-router-in-next-js-d452c43c8bb6?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d452c43c8bb6</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 11:16:48 GMT</pubDate>
            <atom:updated>2026-07-23T11:16:48.669Z</atom:updated>
            <content:encoded><![CDATA[<p>If you recently started learning <strong>Next.js</strong>, you have probably come across A<strong>pp</strong> and P<strong>ages</strong> R<strong>outer</strong> and might have gotten a bit confused.</p><p>Some tutorials use a Pages folder while others use an App folder.</p><p><strong><em>So what should you use?</em></strong></p><h3>Pages Router</h3><p>The <strong>Pages Router</strong> is the original routing system in <strong>Next.js</strong></p><p>Every file inside the pages folder automatically becomes a route.</p><p><em>Common Example:</em></p><pre>pages/<br>  - index.js<br>  - about.js<br>  - contact.js</pre><p>This gives you the following routes:</p><ul><li>/</li><li>/about</li><li>/contact</li></ul><h3>App Router</h3><p>The <strong>App Router</strong> is the newer way of building <strong>Next.js</strong> applications.</p><p>Instead of using pages, you create an <strong>app folder</strong>.</p><pre>app/<br>  - page.js<br>  /about/<br>    - a-page.js<br>  /contact/<br>    - c-page.js</pre><p>The routes are the exact same, but the App Router has some very useful features:</p><ul><li>Layouts can be shared between pages</li><li>Server Components are by default</li><li>Better loading and error handling</li><li>More flexibility for larger apps</li></ul><p>This is slightly different than Pages Router, but makes organizing projects much cleaner.</p><h3>Which to use??</h3><p>Older projects mainly use Pages Router.</p><p>If starting a new project, the recommendation is App Router. It’s where Next.js is heading, and most new features are built around it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d452c43c8bb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding DOM, React.js, and Next.js]]></title>
            <link>https://medium.com/@hbosnjo/understanding-dom-react-js-and-next-js-fa47a82a8e45?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa47a82a8e45</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Mon, 20 Jul 2026 12:35:16 GMT</pubDate>
            <atom:updated>2026-07-20T12:35:16.544Z</atom:updated>
            <content:encoded><![CDATA[<p>Simple understanding of the topics and a look into the differences.</p><h3>What is DOM?</h3><p>DOM stands for Document Object Model.</p><p>Think of the DOM as a tree that the browser creates from your HTML. Every element on the page becomes an object that JavaScript can access and change.</p><p>If you have:</p><pre>&lt;h1&gt;Hello World&lt;/h1&gt;<br>&lt;button&gt;Click Me&lt;/button&gt;</pre><p>The browser doesn’t just see text. It creates objects for <strong>&lt;h1&gt;</strong> and <strong>&lt;button&gt;</strong>, making them part of the <strong>DOM</strong>.</p><p>This allows JavaScript to interact with the webpage after it has loaded.</p><h3>How JavaScript interacts with the DOM</h3><p>JavaScript can:</p><ul><li>Change text</li><li>Change styles</li><li>Create new elements</li><li>Remove elements</li><li>Listen for user actions like clicks or typing</li></ul><p>For example:</p><pre>document.querySelector(&quot;h1&quot;).textContent = &quot;Welcome!&quot;;</pre><p>The browser finds the <strong>&lt;h1&gt;</strong> element in the <strong>DOM</strong> and changes its text from ‘<em>Hello World</em>’ to ‘<em>Welcome!’</em></p><p>You can also change colors:</p><pre>document.querySelector(&quot;h1&quot;).style.color = &quot;blue&quot;;</pre><p>Or respond to button clicks:</p><pre>document.querySelector(&quot;button&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br> alert(&quot;Button clicked!&quot;);<br>});</pre><p>This is how your website becomes interactive instead of just static pages.</p><h3>What is Virtual DOM?</h3><p>Updating the real DOM is very expensive. Every time something changes, the browser has to update the page.</p><p>The Virtual DOM is a lightweight copy of the real DOM.</p><p>Here’s what happens:</p><ol><li>Something changes in your website.</li><li>React updates the Virtual DOM.</li><li>React compares the new Virtual DOM with the previous one.</li><li>It figures out exactly what changed.</li><li>Only those specific changes are applied to the real DOM.</li></ol><p>Instead of rebuilding the whole page, React only updates what actually needs updating.</p><h3>React.js vs. Next.js</h3><h4>What is React.js?</h4><p>React is a JavaScript library used to build user interfaces.</p><p>It focuses on creating reusable <strong>components</strong>.</p><p>Instead of writing the same button five times, you can create one Button <strong>component</strong> and use it wherever you need.</p><p>React mainly handles what users see on the screen.</p><h4>What is Next.js?</h4><p>Next.js is a framework built on top of React.</p><p>It includes everything React has, but also features like:</p><ul><li>Routing between pages</li><li>Server-side rendering (SSR)</li><li>Static site generation (SSG)</li><li>API routes</li><li>Better SEO</li><li>Faster page loading</li></ul><p>Think of it like, React gives you the lego bricks, Next.js gives you the bricks with some building tools.</p><h4>Key differences</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CM9d2N_Z4xLpvubg-cfQEw.png" /></figure><h4>When should you use React?</h4><p>React is a great choice when:</p><ul><li>You’re learning frontend development.</li><li>You’re building a simple web application.</li><li>Your project doesn’t need SEO.</li><li>You want full control over the project setup.</li></ul><p><em>Examples</em> (dashboards, internal company tools, or small applications)</p><h4>When should you use Next.js?</h4><p>Next.js is usually the better choice when:</p><ul><li>You want good SEO.</li><li>Your website needs fast loading.</li><li>You’re building a production website.</li><li>You need multiple pages.</li><li>You want server-side rendering or static generation.</li></ul><p><em>Examples</em> (company websites, blogs, online stores, and portfolio websites)</p><h3>In Short…</h3><p>The DOM is what allows JavaScript to interact with a webpage. Every button, heading, image, and paragraph becomes part of the DOM, giving JavaScript the ability to change them whenever needed.</p><p>React makes working with the DOM much easier by using the Virtual DOM, which updates only the parts of the page that actually change. This improves performance and makes applications feel faster.</p><p>Finally, React and Next.js work together rather than compete. React is the library used to build interfaces, while Next.js builds on React by adding powerful features like routing, server-side rendering, and better performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa47a82a8e45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding APIs, Networking, and Web Security]]></title>
            <link>https://medium.com/@hbosnjo/understanding-apis-networking-and-web-security-a598b9447d76?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a598b9447d76</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Wed, 15 Jul 2026 12:43:07 GMT</pubDate>
            <atom:updated>2026-07-15T12:43:07.716Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will cover the basics of each concept, what problem it solves, and when its used.</p><h3>What are WebSockets?</h3><p>WebSockets create a persistent, two-way connection between a client and server. Instead of using HTTP and having a million requests and responses its a persistent connection both ways.</p><h4>HTTP</h4><ul><li>Request, Response structure</li><li>Connection closes after each request</li><li>Client must start communication</li></ul><h4>WebSockets</h4><ul><li>Persistent two way communication</li><li>Client or Server can send data at any time</li></ul><h4>Common Uses</h4><ul><li>Chats</li><li>Multiplayer games</li><li>Live dashboards</li><li>Stock prices</li></ul><h3>HTTP, HTTPS, and TLS</h3><h4>HTTP</h4><p>HyperText Transfer Protocol (HTTP) is the standard way browsers and servers communicate.</p><p>Whenever you visit a website or call an API, HTTP is usually being used. The one downside to HTTP is that all data is in plaintext, meaning anyone can read and modify it.</p><h4>HTTPS</h4><p>The exact same as HTTP but with <strong>Security </strong>that encrypts all communication between the client and server.</p><h4>TLS</h4><p>TLS is a protocol that makes HTTPS secure. It has two main jobs:</p><ul><li>Encrypt communication between the client and server</li><li>Verify the server identity using digital certificates</li></ul><h3>What is CORS?</h3><p><strong>Cross-Origin Resource Sharing (CORS).</strong></p><p>Is a browser security feature that controls which websites are allowed to access and API. By default, browsers block requests made from one domain to another, unless the server allows it.</p><h4>Why do we need it?</h4><p>Without CORS malicious websites could make requests to other websites where you’re already logged in.</p><h3>SQL Injection</h3><p>SQL injection is when an attacker enters SQL code into an input field and the application treats it as part of a database query.</p><h4>Risks</h4><ul><li>Read database data</li><li>Modify data</li><li>Delete data</li><li>Bypass authentication</li></ul><h4>Prevention</h4><ul><li>Use parameterized queries</li><li>Use prepared statements</li><li>use an ORM</li></ul><h3>Cross-Site Scripting (XSS)</h3><p>XSS happens when an application displays user input without properly sanitizing it. An attacker can inject JavaScript that runs in another user’s browser.</p><h4>Risks</h4><ul><li>Steal cookies</li><li>Redirect users</li><li>Modify page content</li><li>Impersonate users</li></ul><h4>Prevention</h4><ul><li>Escape HTML output</li><li>Sanitize user input</li><li>Validate data before displaying it</li></ul><h3>Cross-Site Request Forgery (CSRF)</h3><p>CSRF tricks a logged-in users browser into sending requests they never intended to make. Since the broswer automatically includes login cookies, the server may think the request came from the user.</p><p>To prevent this we use CSRF tokens. A valid token must be included with sensitive requests, preventing attackers from forging them.</p><h3>Rate Limiting</h3><p>Rate limiting controls how many requests a client can make within a time period. For example:</p><ul><li>100 requests</li><li>Every 15 minutes</li></ul><p>If this limit is exceeded, the server rejects additional requests.</p><h4>Why?</h4><p>Rate limiting protects against:</p><ul><li>Brute-force login attempts</li><li>API abuse</li><li>Spam requests</li><li>DDos attacks</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a598b9447d76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB Relationships, Transactions, and Performance]]></title>
            <link>https://medium.com/@hbosnjo/mongodb-relationships-transactions-and-performance-5a86d992d0cd?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a86d992d0cd</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Sun, 12 Jul 2026 08:20:04 GMT</pubDate>
            <atom:updated>2026-07-12T08:20:04.319Z</atom:updated>
            <content:encoded><![CDATA[<p>These topics focus on designing efficient databases, maintaining data consistency, and ensuring the app remains fast.</p><h3>MongoDB Relationships</h3><p>Since MongoDB is built on documents and not tables with joins and relationships, we have two main approaches to using relationships.</p><h4>Embedding Documents</h4><p>Embedding stores related information inside a single document.</p><pre>{<br>  &quot;_id&quot;: 1,<br>  &quot;name&quot;: &quot;Alice&quot;,<br>  &quot;address&quot;: {<br>    &quot;city&quot;: &quot;Riyadh&quot;,<br>    &quot;country&quot;: &quot;Saudi Arabia&quot;<br>  }<br>}</pre><p>Advantages:</p><ul><li>Faster read</li><li>No extra queries needed</li><li>Simpler structure</li></ul><p>Best used when:</p><ul><li>Related data is small</li><li>Related data is always accessed together</li></ul><h4>Referencing Documents</h4><p>Referencing stores related information in seperate collections using document IDs.</p><pre>{<br>  &quot;_id&quot;: 1,<br>  &quot;name&quot;: &quot;Alice&quot;<br>}</pre><p><em>User Collection^</em></p><pre>{<br>  &quot;_id&quot;: 101,<br>  &quot;userId&quot;: 1, // Reference to other collection<br>  &quot;total&quot;: 450<br>}</pre><p><em>Order Collection^</em></p><p><strong>Advantages</strong>:</p><ul><li>Reduces duplicate data</li><li>Easier to update shared information</li><li>Better for large or often changing databases</li></ul><p><strong>Best used when:</strong></p><ul><li>Documents are very large</li><li>Multiple documents share the same data</li><li>Relationships are many-to-many</li></ul><h4>Relationship Types</h4><h4>One-to-One</h4><p>When a single document is related to one other. (e.g. <strong>User</strong> <em>related to</em> <strong>Profile</strong>)</p><h4>One-to-Many</h4><p>A single document related to multiple others. (e.g. <strong>Customer</strong> <em>related to</em> <strong>Orders</strong> 1, 2, 3, …)</p><h4>Many-to-Many</h4><p>Both sides have multiple related documents. (e.g. <strong>Students</strong> <em>related to</em> <strong>Courses</strong>)</p><h4>When to choose which?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzpN4taBcTp99HVAx5ZUtA.png" /></figure><p>Not a single one is the best for every case. The right choice depends on how you access and update your data.</p><h3>MongoDB Transactions</h3><p>A transaction is a group of database operations treated as a single unit of work. MongoDB follows the <strong>ACID</strong> principles in this matter.</p><h4>What is ACID?</h4><p><strong>A</strong>tomicity:</p><ul><li>All operations succeed or fail together</li></ul><p><strong>C</strong>onsistency:</p><ul><li>Data remains valid before and after the transaction</li></ul><p><strong>I</strong>solation:</p><ul><li>Transactions fo not interfere with one another</li></ul><p><strong>D</strong>urability:</p><ul><li>Committed changes are permanently stored</li></ul><h4>Why do we need transactions?</h4><p>Instead of doing one action at a time manually with no error protection, we use transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*VXfSvc7ej8DVkIwK2UoEig.png" /></figure><p><em>If any step fails:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*f8SdNAXoT6YWvh-RlUUb1Q.png" /></figure><h4>Sessions</h4><p><strong>Transactions</strong> execute within a <strong>session</strong>. So what do sessions do?</p><p><strong>Sessions</strong> track every operation until you commit or abort. This allows MongoDB to safely apply or discard all changes together.</p><h4>When to Use Transactions</h4><p>Transactions are ideal for operations involving multiple documents or collections, such as:</p><ul><li>Banking systems</li><li>E-commerce checkouts</li><li>Inventory management</li><li>Booking / Reservation systems</li></ul><h3>MongoDB Performance</h3><p>As databases grow, efficient queries become very important. Performance optimization ensures that everything stays responsive while handling large amounts of data.</p><h4>Indexes</h4><p>Indexes allow MongoDB to locate matching documents without scanning an entire collection. Which significantly improves read performance, but requires additional storage and slightly increases the cost of write operations.</p><p><em>Without an index:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eV5lt8BHqispjpYIlIy0Wg.png" /></figure><p><em>With an index:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1A_u9903hvMX2iXTR0BMQ.png" /></figure><h4>Query Optimization</h4><p>Proper written queries reduce processing time and improve overall performance.</p><p>Best practices:</p><ul><li>Filter documents whenever possible</li><li>Retrieve only the fields you need</li><li>Avoid unnecessary sorting on large collections</li><li>Use indexes on frequently accessed fields</li></ul><h4>Using explain()</h4><p>MongoDB provides <strong>explain()</strong> to analyze how a query executes.</p><p>It can show:</p><ul><li>The execution plan</li><li>Wether an index is being used</li><li>Number of documents scanned</li><li>Query execution time</li></ul><p>This helps identify inefficient queries and opportunities for optimization.</p><h4>Pagination</h4><p>Returning thousands of documents in a single request is slow, instead we use pagination to return results in smaller batches.</p><p>Common approaches:</p><ul><li><strong>skip()</strong> and <strong>limit()</strong> for simple pagination</li><li>Cursor-based pagination for large datasets, which offers better performance and consistency</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a86d992d0cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is MongoDB? simply.]]></title>
            <link>https://medium.com/@hbosnjo/what-is-mongodb-simply-2a1e94c01646?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a1e94c01646</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Sun, 05 Jul 2026 11:31:52 GMT</pubDate>
            <atom:updated>2026-07-05T11:31:52.800Z</atom:updated>
            <content:encoded><![CDATA[<p>MongoDB is a NoSQL document based database that stores data as BSON documents.</p><p>Compared to SQL which stores data in <strong>tables</strong> with <strong>rows</strong> and <strong>columns</strong>, MongoDB stores in <strong>collections</strong> with <strong>documents</strong> and <strong>fields</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SLyynDa98YS-WWyH3FSe7w.png" /></figure><h4>SQL :</h4><pre>Users Table<br><br>ID | Name   | Age<br>------------------<br>1  | Hamzah | 21</pre><h4>MongoDB :</h4><pre>{<br>  &quot;_id&quot;: fau37hfui109fn3189mf131,<br>  &quot;name&quot;: &quot;Hamzah&quot;,<br>  &quot;age&quot;: 21<br>}</pre><h3>Documents</h3><p>Documents are MongoDB’s version of a row in SQL. Each object represents a single record, as show in the example above.</p><p>Each individual piece of information is called a field (e.g. “_id:” “faw255f”).</p><p>Documents can contain arrays and even other documents:</p><pre>{<br>  &quot;name&quot;: &quot;Hamzah&quot;,<br>  &quot;hobbies&quot;: [<br>    &quot;Coffee&quot;,<br>    &quot;Hiking&quot;,<br>    &quot;Reading&quot;<br>  ]<br>}</pre><p>Embedded Documents:</p><pre>{<br>  &quot;name&quot;: &quot;Hamzah&quot;,<br>  &quot;address&quot;: {<br>    &quot;city&quot;: &quot;Riyadh&quot;,<br>    &quot;country&quot;: &quot;Saudi Arabia&quot;<br>  }<br>}</pre><p>Documents are more flexible than relational databases as they can contain fields, arrays, and even embedded documents.</p><h3>Collections</h3><p>Collections are groups of documents, almost like folders, they are comparable to tables in SQL.</p><p>A benefit to collections is that the documents dont have to be identical (they dont have to have the same field).</p><pre>{<br>  &quot;name&quot;: &quot;Hamzah,<br>  &quot;age&quot;: 21,<br>}<br><br>{<br>  &quot;name&quot;: &quot;Khalid&quot;,<br>  &quot;email&quot;: &quot;khalid@gmail.com&quot;,<br>}</pre><p>Although we have this flexibility in MongoDB, it is better practice to enforce a consistent structure using Mongoose schemas.</p><h3>Databases</h3><p>Databases are containers that hold multiple collections, just like in SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*51VqurrtGWmNZfhXhPGCPg.png" /></figure><p>Each database contains multiple collections, which then contain multiple documents, which finally contain multiple fields.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a1e94c01646" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modules: What Are They?]]></title>
            <link>https://medium.com/@hbosnjo/modules-what-are-they-25ac2dcdcf89?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/25ac2dcdcf89</guid>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Wed, 01 Jul 2026 12:20:51 GMT</pubDate>
            <atom:updated>2026-07-01T12:21:09.954Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will discusses modules in Node.js, looking at CommonJs (CJS) &amp; ES Modules (ESM)</p><h4>What Are Modules?</h4><p>Think of modules like lego blocks, each is different in its own way, each has a specific purpose/responsibility. We then use them together to build amazing things, modules are the same.</p><ul><li>Modules split code into reusable files (math.js, database.js, etc…)</li><li>Each module has a specific responsibility</li><li>Modules help improve organization and maintainability</li></ul><h4>What is CommonJS (CJS)?</h4><p>CommonJS (CJS) is the original module system for Node.js, as it was introduced before JavaScript had an official module system.</p><ul><li>Uses <strong><em>require()</em></strong><em> </em>to import modules</li><li>Uses <strong><em>module.exports</em></strong> to export modules</li><li>Used mainly in older Node projects (good to learn, not use)</li></ul><h4>What are ES Modules (ESM)?</h4><p>ES Modules (ESM) are JavaScript’s official module system, and was introduced as part of the JavaScript standard.</p><ul><li>Uses <strong><em>import</em></strong> to import modules</li><li>Uses <strong><em>export</em></strong> to export them</li><li>Is the standard for modern JS applications, supported by Node.js &amp; browsers</li></ul><h4>CommonJS Module Usage</h4><pre>function add(a, b) {<br>  return a + b;<br>}<br><br>module.exports = add;</pre><p><em>This our math.js file, which we are exporting from</em></p><pre>const add = require(&#39;./math&#39;);<br><br>console.log(add(2, 3));</pre><p><em>This is our index.js file, where we are importing from math.js</em></p><h4>ES Modules Usage</h4><pre>export function add(a, b) {<br>  return a + b;<br>}</pre><p><em>This is our new math.js file, where we directly export functions</em></p><pre>import { add } from &#39;./math.js&#39;;<br><br>console.log(add(2, 3));</pre><p><em>This is the new index.js, where we use the ESM import method</em></p><h4>CommonJS vs ES Modules</h4><pre>| Feature | CommonJS (CJS)                  | ES Modules (ESM)                        |<br>|---------|---------------------------------|-----------------------------------------|<br>| Origin  | Node.js&#39; original module system | JavaScript&#39;s official module system     |<br>| Import  | `require()`                     | `import`                                |<br>| Export  | `module.exports`                | `export`                                |<br>| Usage   | Older Node.js projects          | Modern JavaScript applications          |<br>| Support | Node.js                         | Node.js and browsers                    |</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_JpKl-PMLzuMu9VGTlgtQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25ac2dcdcf89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Express Simply (Part 1)]]></title>
            <link>https://medium.com/@hbosnjo/understanding-express-simply-part-1-75908f1f98e5?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/75908f1f98e5</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 13:43:34 GMT</pubDate>
            <atom:updated>2026-06-24T13:43:34.627Z</atom:updated>
            <content:encoded><![CDATA[<p>Assuming you have an understanding of javaScript.</p><p>Make sure you have Express installed and the following code:</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const port = 3000;<br>const path = require(&#39;path&#39;);<br><br>// GET request to homepage<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World!&#39;);<br>});<br><br>// Start server<br>app.listen(port, () =&gt; {<br>  console.log(`Example app listening on port ${port}`);<br>});</pre><p><em>^This will be your index.js^</em></p><h3>1. Routing</h3><h4>1.1 Basic Routes</h4><p>A route defines how the server responds to a request.</p><p>Structure:</p><pre>app.METHOD(PATH, HANDLER);</pre><p>Where:</p><ul><li>METHOD = GET, POST, PUT, DELETE, etc.</li><li>PATH = URL path</li><li>HANDLER = function that runs when the route is matched</li></ul><h4>Using Your Current Code</h4><p>You already have your first route:</p><pre>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World!&#39;);<br>});</pre><p>Lets break it down:</p><ul><li>app.get() listens for GET requests</li><li>&#39;/&#39; is the homepage</li><li>req contains information about the request</li><li>res is used to send a response</li><li>res.send() sends text back to the client</li></ul><h4>What Happens?</h4><p>Browser:</p><pre>http://localhost:3000/</pre><p>Request:</p><pre>GET /</pre><p>Response:</p><pre>Hello World!</pre><h4>Key Takeaway</h4><p>Every Express route needs:</p><pre>app.get(&#39;/path&#39;, (req, res) =&gt; {<br>  res.send(&#39;Response&#39;);<br>});</pre><h4>Don’t change anything yet.</h4><p>Run:</p><pre>node index.js</pre><p>Then visit:</p><pre>http://localhost:3000</pre><h3>1.2 Route Paths</h3><p>A route path is the URL that Express matches.</p><p>For example:</p><pre>/<br>about<br>contact<br>products</pre><p>When a request comes in, Express checks the path and runs the matching route handler.</p><h4>Update Your Code</h4><p>Add to your current code (type it yourself):</p><pre>// About page<br>app.get(&#39;/about&#39;, (req, res) =&gt; {<br>  res.send(&#39;About Page&#39;);<br>});<br>// Contact page<br>app.get(&#39;/contact&#39;, (req, res) =&gt; {<br>  res.send(&#39;Contact Page&#39;);<br>});</pre><h4>What Happens?</h4><p>Request:</p><pre>GET /about</pre><p>Response:</p><pre>About Page</pre><p>Request:</p><pre>GET /contact</pre><p>Response:</p><pre>Contact Page</pre><h4>Test</h4><p>Visit <em>(run node index.js)</em>:</p><pre>http://localhost:3000/<br>http://localhost:3000/about<br>http://localhost:3000/contact</pre><h4>Key Takeaway</h4><p>Routes are matched by both:</p><ul><li>HTTP method</li><li>Path</li></ul><h3>1.3 Route Parameters</h3><p>Route parameters allow part of the URL to be dynamic.</p><p>Instead of creating a million URL’s:</p><pre>/users/1<br>/users/2<br>/users/3<br>...</pre><p>You create one route:</p><pre>/users/:id</pre><p>Express captures the value and stores it in req.params.</p><h4>Update Your Code</h4><p>Add this below your existing routes:</p><pre>// User profile<br>app.get(&#39;/users/:id&#39;, (req, res) =&gt; {<br>  res.send(`User ID: ${req.params.id}`);<br>});</pre><h4>What Happens?</h4><p>Request:</p><pre>GET /users/5</pre><p>Response:</p><pre>User ID: 5</pre><p>Request:</p><pre>GET /users/42</pre><p>Response:</p><pre>User ID: 42</pre><h4>Multiple Parameters</h4><p>Add one more route after User profile:</p><pre>// Product review<br>app.get(&#39;/products/:productId/reviews/:reviewId&#39;, (req, res) =&gt; {<br>  res.send(<br>    `Product: ${req.params.productId}, Review: ${req.params.reviewId}`<br>  );<br>});</pre><h4>What Happens?</h4><p>Request:</p><pre>GET /products/10/reviews/3</pre><p>Response:</p><pre>Product: 10, Review: 3</pre><h4>Test it</h4><p>Run <em>node index.js</em> and go to:</p><pre>http://localhost:3000/users/1<br>http://localhost:3000/users/99</pre><pre>http://localhost:3000/products/10/reviews/3<br>http://localhost:3000/products/25/reviews/7</pre><h4>Key Takeaway</h4><p>Parameters are defined with <strong>:</strong><em>parameter</em></p><pre>app.get(&#39;/users/:id&#39;, ...)</pre><p>and accessed through:</p><pre>req.params.id</pre><p>For multiple parameters:</p><pre>req.params.productId<br>req.params.reviewId</pre><h3>1.4 Route Handlers</h3><p>A route handler is the function that runs when a route is matched.</p><p>So far you’ve used one handler:</p><pre>app.get(&#39;/about&#39;, (req, res) =&gt; {<br>  res.send(&#39;About Page&#39;);<br>});</pre><p>Express also allows multiple handlers for the same route.</p><p>This is useful when you want one function to do some work and then pass control to another function.</p><h4>Update Your Code</h4><p>Add these <strong>functions</strong> above your <strong>routes</strong>:</p><pre>function logRequest(req, res, next) {<br>  console.log(&#39;Request received&#39;);<br>  next();<br>}<br>Now add this route:</pre><pre>function sendResponse(req, res) {<br>  res.send(&#39;Route handler completed&#39;);<br>}</pre><p>Also add this <strong>route</strong>:</p><pre>app.get(&#39;/handler-demo&#39;, logRequest, sendResponse);</pre><h4>What Happens?</h4><p>Request:</p><pre>GET /handler-demo</pre><p>Console:</p><pre>Request received</pre><p>Browser Response:</p><pre>Route handler completed</pre><h3>Understanding next()</h3><p>Without this:</p><pre>next();</pre><p>Express would stop at the first handler.</p><p>This works:</p><pre>function logRequest(req, res, next) {<br>  console.log(&#39;Request received&#39;);<br>  next();<br>}</pre><p>But this hangs forever:</p><pre>function logRequest(req, res, next) {<br>  console.log(&#39;Request received&#39;);<br>}</pre><p>because Express never moves to the next handler and no response is sent.</p><h4>Multiple Inline Handlers</h4><p>You can also write:</p><pre>app.get(&#39;/inline-demo&#39;, (req, res, next) =&gt; {<br>    console.log(&#39;First handler&#39;);<br>    next();<br>  },<br>  (req, res) =&gt; {<br>    res.send(&#39;Second handler&#39;);<br>  }<br>);</pre><h4>Test it</h4><p>Visit:</p><pre>http://localhost:3000/handler-demo<br>http://localhost:3000/inline-demo</pre><p>Watch both:</p><ul><li>Browser response</li><li>Terminal output</li></ul><h4>Key Takeaway</h4><p>A route can have:</p><pre>app.get(path, handler);</pre><p>or</p><pre>app.get(path, handler1, handler2);</pre><p>or even</p><pre>app.get(path, handler1, handler2, handler3);</pre><p>next() tells Express:</p><p>“I’m done, run the next handler.”</p><p>This is the foundation of middleware, which is going to be next major topic after Routing.</p><h3>1.5 Response Methods</h3><p>The res (response) object is how Express sends data back to the client.</p><p>So far you’ve used:</p><pre>res.send()</pre><p>But Express provides several response methods depending on what you want to return.</p><h4>res.send()</h4><p>Sends text, HTML, or other simple responses.</p><p>Add if you want:</p><pre>app.get(&#39;/send&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello from res.send()&#39;);<br>});</pre><p>Then visit:</p><pre>http://localhost:3000/send</pre><h4>res.json()</h4><p>Sends JSON.</p><p>Add:</p><pre>app.get(&#39;/json&#39;, (req, res) =&gt; {<br>  res.json({<br>    name: &#39;Hamzah&#39;,<br>    role: &#39;Intern&#39;<br>  });<br>});</pre><p>Then visit:</p><pre>http://localhost:3000/json</pre><p>Response:</p><pre>{<br>  &quot;name&quot;: &quot;Hamzah&quot;,<br>  &quot;role&quot;: &quot;Intern&quot;<br>}</pre><h4>res.status()</h4><p>Sets the HTTP status code.</p><p>Add:</p><pre>app.get(&#39;/status&#39;, (req, res) =&gt; {<br>  res.status(404).send(&#39;Page not found&#39;);<br>});</pre><p>Visit:</p><pre>http://localhost:3000/status</pre><p>Response body:</p><pre>Page not found</pre><p>Status code (check your browser terminal):</p><pre>404</pre><h4>res.redirect()</h4><p>Redirects the client to another route.</p><p>Add:</p><pre>app.get(&#39;/old-home&#39;, (req, res) =&gt; {<br>  res.redirect(&#39;/&#39;);<br>});</pre><p>Visit:</p><pre>http://localhost:3000/old-home</pre><p>You’ll be redirected to:</p><pre>http://localhost:3000/</pre><h4>res.sendFile()</h4><p>Sends a file.</p><p>Create a new folder named public and add a file to it called hello.html:</p><pre>public/<br>└── hello.html</pre><p>hello.html code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;Hello&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;Hello from HTML&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Add this route to your index.js:</p><pre>app.get(&#39;/file&#39;, (req, res) =&gt; {<br>  res.sendFile(path.join(__dirname, &#39;public&#39;, &#39;hello.html&#39;));<br>});</pre><p>This is why we kept:</p><pre>const path = require(&#39;path&#39;);</pre><p>Visit to see the result:</p><pre>http://localhost:3000/file</pre><h4>Key Takeaway</h4><p>Most common response methods:</p><pre>res.send()<br>res.json()<br>res.status()<br>res.redirect()<br>res.sendFile()</pre><h3>1.6 Express Router</h3><p>Right now all routes are inside index.js.</p><p>As applications grow, this becomes difficult to maintain.</p><p>express.Router() allows us to group related routes into separate files and then import them into the main application.</p><p>Instead of containing all routes:</p><pre>index.js<br>├── 5 routes<br>├── 10 routes<br>├── 20 routes<br>└── ...</pre><p>We can do a folder with individual route files:</p><pre>routes/<br>└── users.js</pre><p>and keep user-related routes together.</p><h4>Create a New Folder and File</h4><pre>routes/<br>└── users.js</pre><h4>Create routes/users.js</h4><p>Add this code to it:</p><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();<br><br>// GET /users<br>router.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Users Home&#39;);<br>});<br><br>// GET /users/profile<br>router.get(&#39;/profile&#39;, (req, res) =&gt; {<br>  res.send(&#39;User Profile&#39;);<br>});<br><br>module.exports = router;</pre><h4>Update index.js</h4><p>Add this near the top with your other imports:</p><pre>const usersRouter = require(&#39;./routes/users&#39;);</pre><p>Add this above app.listen():</p><pre>app.use(&#39;/users&#39;, usersRouter);</pre><h3>What Happens</h3><p>When Express sees:</p><pre>app.use(&#39;/users&#39;, usersRouter);</pre><p>it automatically prefixes all routes inside the router with:</p><pre>/users</pre><h4>Router Route</h4><pre>router.get(&#39;/&#39;, ...)</pre><p>becomes:</p><pre>/users</pre><h4>Router Route</h4><pre>router.get(&#39;/profile&#39;, ...)</pre><p>becomes:</p><pre>/users/profile</pre><h4>Test it</h4><p>Visit:</p><pre>http://localhost:3000/users</pre><p>Response should be:</p><pre>Users Home</pre><p>Visit:</p><pre>http://localhost:3000/users/profile</pre><p>Response:</p><pre>User Profile</pre><h4>Key Takeaway</h4><p>A router is a mini Express application.</p><p>Create:</p><pre>const router = express.Router();</pre><p>Define routes:</p><pre>router.get(...)<br>router.post(...)</pre><p>Export:</p><pre>module.exports = router;</pre><p>Mount in index.js:</p><pre>app.use(&#39;/users&#39;, usersRouter);</pre><p>Thats the end of this part, next part will be on writing middleware.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75908f1f98e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[REST, GraphQL, and Web Sessions]]></title>
            <link>https://medium.com/@hbosnjo/rest-graphql-and-web-sessions-592c1d9a5a10?source=rss-cf9e3e90262d------2</link>
            <guid isPermaLink="false">https://medium.com/p/592c1d9a5a10</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[graphql-vs-rest]]></category>
            <dc:creator><![CDATA[Hamzah]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 07:48:42 GMT</pubDate>
            <atom:updated>2026-06-24T07:48:42.043Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is the main difference between REST and GraphQL, and in which scenarios would you prefer one over the other?</h3><h4>Rest</h4><ul><li>Uses multiple endpoints and requests</li><li>Good for returning simple and predictable data structures</li><li>Returns all available data from an endpoint, not just the data requested</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yNWaO0o1CLYG4OjDg-fyIw.png" /><figcaption>Rest call example</figcaption></figure><h4>GraphQL</h4><ul><li>Returns only the requested field</li><li>Reduces the number of API calls</li><li>Useful when data is needed from multiple resources</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nmn6EZ8uKltKxpDrPHUsiw.png" /><figcaption>GraphQL call example</figcaption></figure><h3>What do the terms Over-fetching and Under-fetching mean in REST API’s, and how does GraphQL address these issues?</h3><h4>Over-fetching</h4><ul><li>Receiving more data than needed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5j_WT-zXjDzc95wBA-2Ow.png" /><figcaption>Over-fetching example</figcaption></figure><h4>Under-fetching</h4><ul><li>Receiving too little data, requiring additional requests</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kAAuYCTD7pY9DvawjlubrQ.png" /><figcaption>Under-fetching example</figcaption></figure><h4>How GraphQL solves this</h4><ul><li>Allows clients to request only the required fields</li><li>Combines related data into a single request</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwYx9TqHhnwSW6K1oNRRfQ.png" /><figcaption>GraphQL fetching solution</figcaption></figure><h3>Since HTTP is a stateless protocol, how do modern web applications keep users logged in and remember shopping cart items as they navigate through the application?</h3><h4>Cookies</h4><ul><li>Store data in the browser</li></ul><h4>Json Web Tokens (JWT)</h4><ul><li>Store user authentication information in a signed token</li></ul><h4>Session ID’s</h4><ul><li>Store a session ID that identifies the user</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7JPnAp2KypTkwIzP-bKoqw.png" /><figcaption>Session ID Storage example</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=592c1d9a5a10" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>