<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Siddharth Gujrathi</title>
    <description>The latest articles on DEV Community by Siddharth Gujrathi (@siddharth_g).</description>
    <link>https://dev.to/siddharth_g</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1100358%2Fe01e31d0-1aa1-4ce8-849b-26a9fdaf8fdf.jpg</url>
      <title>DEV Community: Siddharth Gujrathi</title>
      <link>https://dev.to/siddharth_g</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/siddharth_g"/>
    <language>en</language>
    <item>
      <title>Express 5 Brings Built-in Promise Support for Error Handling</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Fri, 04 Apr 2025 09:59:36 +0000</pubDate>
      <link>https://dev.to/siddharth_g/express-5-brings-built-in-promise-support-for-error-handling-5bjf</link>
      <guid>https://dev.to/siddharth_g/express-5-brings-built-in-promise-support-for-error-handling-5bjf</guid>
      <description>&lt;p&gt;Recently, in October, the Express team announced the release of &lt;strong&gt;Express 5&lt;/strong&gt;, a long-awaited update that brings several new features and improvements.&lt;/p&gt;

&lt;p&gt;After nearly a decade of development, Express 5 is finally here! The commitment to releasing a major version after such a long time demonstrates the framework's stability and the team's dedication to keeping it aligned with modern JavaScript standards and best practices.&lt;/p&gt;

&lt;p&gt;One feature that particularly caught my attention is &lt;strong&gt;native support for Promises&lt;/strong&gt;. When I first read about it, I was both surprised and intrigued by its simplicity—and it left me wondering why it hadn't been implemented earlier.&lt;/p&gt;

&lt;p&gt;Before diving into this feature, I recommend reviewing the following prerequisite topics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises" rel="noopener noreferrer"&gt;Promises&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await" rel="noopener noreferrer"&gt;Async/Await&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/en/guide/using-middleware.html" rel="noopener noreferrer"&gt;Middleware in Express&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/en/guide/error-handling.html" rel="noopener noreferrer"&gt;Error Handling in Express&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Express 5 Promise Support
&lt;/h2&gt;

&lt;p&gt;According to the Express documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The main change in Express 5 regarding Promise support is the addition of basic support for returned, rejected Promises in the router."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, Express 5 now &lt;strong&gt;automatically handles rejected Promises from middleware and route handlers&lt;/strong&gt;, eliminating the need for explicit error handling with &lt;code&gt;next(error)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Did Express Not Support Promises Before?
&lt;/h3&gt;

&lt;p&gt;Yes, we could use Promises in Express 4, but handling errors required manually passing them to the next middleware using &lt;code&gt;next(error)&lt;/code&gt;. This approach often led to redundant &lt;strong&gt;try-catch&lt;/strong&gt; blocks, making the code more verbose and less maintainable.&lt;/p&gt;

&lt;p&gt;Let's look at how error handling was done in &lt;strong&gt;Express 4&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Express 4: Traditional Error Handling
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example Code (Express 4)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Using Express 4.21.2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8181&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj@vision-media.ca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaran&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaranj@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron.heckmann+github@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getUserById&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Explicit error passing&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getUserById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Viewing user &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Received error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Problems with Express 4 Error Handling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Boilerplate Code&lt;/strong&gt;: Every async middleware or route handler needed &lt;strong&gt;try-catch&lt;/strong&gt; blocks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit Error Forwarding&lt;/strong&gt;: Errors had to be manually passed to &lt;code&gt;next(error)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redundant Code&lt;/strong&gt;: Many functions contained repetitive error handling logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A Workaround: Using an Error Handling Wrapper
&lt;/h3&gt;

&lt;p&gt;A common way to reduce repetition was to create a wrapper function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Using 4.21.2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8181&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Dummy users&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj@vision-media.ca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaran&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaranj@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron.heckmann+github@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// A wrapper function to handle errors in async handlers and pass them to the next middleware(error handler)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleErrorWrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;res&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="na"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Simulating method to get user by ID from the database&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getUserById&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed to load user &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;andRestrictTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Received the error in next middleware&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticatedUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticatedUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;handleErrorWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getUserById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Viewing user &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;handleErrorWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;andRestrictTo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Deleted user &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Received the error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Example app listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Express 5: Native Promise Error Handling
&lt;/h2&gt;

&lt;p&gt;With Express 5, we no longer need to manually handle errors in async functions. If a route or middleware returns a rejected Promise, &lt;strong&gt;Express automatically catches and forwards the error&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example Code (Express 5)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8181&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tj@vision-media.ca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaran&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ciaranj@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;member&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaron.heckmann+github@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getUserById&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Database Error: Can't connect to database&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loadUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getUserById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Viewing user &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Received error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why This is a Big Improvement
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cleaner Code&lt;/strong&gt;: No need for &lt;strong&gt;try-catch&lt;/strong&gt; in every async function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Less Boilerplate&lt;/strong&gt;: Eliminates repetitive error handling logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Error Forwarding&lt;/strong&gt;: Express 5 automatically catches rejected Promises and forwards them to error-handling middleware.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better Readability&lt;/strong&gt;: The new approach is more intuitive and aligns with modern JavaScript practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Might This Be Implemented Internally?
&lt;/h2&gt;

&lt;p&gt;The Express 5 team likely implemented this using a mechanism similar to this high-level wrapper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wrapWithErrorHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage:&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This will throw an error&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Something went wrong!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;errorMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Handle the error (e.g., send a response to the client)&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Internal Server Error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrappedFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wrapWithErrorHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;errorMiddleware&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Simulate a request&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="c1"&gt;// Mock request object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;send&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// Mock response object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="c1"&gt;// Mock next function&lt;/span&gt;

&lt;span class="nf"&gt;wrappedFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This concept extends the router and middleware execution to &lt;strong&gt;automatically catch errors in async functions&lt;/strong&gt;, making the framework more resilient and easier to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Express 5’s native support for Promises is a &lt;strong&gt;small but powerful&lt;/strong&gt; improvement that significantly enhances developer experience. It simplifies error handling, improves code readability, and eliminates unnecessary boilerplate.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Productivity with the GTD System by David Allen</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Sun, 13 Oct 2024 10:06:11 +0000</pubDate>
      <link>https://dev.to/siddharth_g/productivity-with-the-gtd-system-by-david-allen-o05</link>
      <guid>https://dev.to/siddharth_g/productivity-with-the-gtd-system-by-david-allen-o05</guid>
      <description>&lt;p&gt;We all know how overwhelming it can be to juggle tasks, ideas, and projects in our minds. That's where David Allen’s &lt;em&gt;Getting Things Done&lt;/em&gt; (GTD) system comes in. It’s a framework designed to organise, track, and complete your tasks and projects effectively, all while helping you maintain a clear and focused mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why GTD?
&lt;/h2&gt;

&lt;p&gt;The entire premise of GTD is built around this key idea:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Your mind is for having ideas, not holding them.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of your brain as a whiteboard. If it's cluttered with to-do lists and “don’t forget” notes, there’s no room for drawing new ideas. GTD is about offloading everything from your brain into a system you can trust. This reduces stress and frees up your mind to focus on what’s truly important, saving you time and boosting productivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Key Components of GTD
&lt;/h2&gt;

&lt;p&gt;To set up GTD, you’ll rely on a few core tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inbox&lt;/strong&gt;: A catch-all for tasks, ideas, notes—everything you need to offload from your mind.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Next Actions&lt;/strong&gt;: The next physical steps to move your tasks forward.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Waiting For&lt;/strong&gt;: A list for tasks or projects that are waiting on someone else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Someday/Maybe&lt;/strong&gt;: Items you might want to do in the future, but aren’t committed to right now.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Projects&lt;/strong&gt;: Any multi-step task with a specific goal or outcome.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference/Resource&lt;/strong&gt;: Non-actionable information that you may need in the future.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calendar&lt;/strong&gt;: For time or date-specific tasks and commitments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All these lists can be created in a task app, a physical notebook, or even in separate folders on your computer. The key is to ensure the system is easy to use so you’ll stick with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 5 Steps of GTD
&lt;/h2&gt;

&lt;p&gt;GTD works by breaking down the workflow into five actionable steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Capture&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Record every idea, task, and note into your Inbox as they occur to you. The goal here is to get everything out of your head.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clarify&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Go through your inbox regularly and ask: "Is this actionable?" If yes, define the next step. If no, file it away as reference or move it to your Someday/Maybe list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Organize&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Put actionable items into the appropriate buckets: Next Actions, Waiting For, Projects, or Calendar. If a task can be done in two minutes or less, do it right away.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reflect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Regularly review your lists, especially during the &lt;em&gt;Weekly Review&lt;/em&gt;, to keep your system up to date and to make sure everything is on track.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Engage&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Finally, choose which task to tackle next based on your context, available time, and energy level.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Contexts: Organising Your Tasks
&lt;/h2&gt;

&lt;p&gt;One way GTD helps you stay productive is by using &lt;em&gt;contexts&lt;/em&gt;—tags that categorise tasks based on where, how, or with what tools you can do them. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“@Errands” for tasks you can do while out and about.&lt;/li&gt;
&lt;li&gt;“&lt;a class="mentioned-user" href="https://dev.to/john"&gt;@john&lt;/a&gt;” for things to discuss in your next meeting with John.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By organising tasks this way, you can quickly find what needs to be done based on your situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Engaging with Your Tasks
&lt;/h2&gt;

&lt;p&gt;Once your system is set up and your tasks are organised, you can confidently engage with your work. At any given time, you’ll fall into one of three types of work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Doing predefined work&lt;/strong&gt;: Completing tasks from your action lists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unplanned work&lt;/strong&gt;: Handling urgent issues that come up unexpectedly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Defining your work&lt;/strong&gt;: Clarifying tasks and deciding on the next actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When it comes to choosing what to do next, use the &lt;strong&gt;Four-Criteria Model&lt;/strong&gt;:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Context&lt;/strong&gt;: Where are you, and what tools are available?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Available&lt;/strong&gt;: How much time do you have before your next commitment?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Energy Available&lt;/strong&gt;: What’s your current energy level?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Priority&lt;/strong&gt;: Which task will have the most impact?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Weekly Review: Your Key to Staying on Track
&lt;/h2&gt;

&lt;p&gt;A crucial part of making GTD work is the &lt;em&gt;Weekly Review&lt;/em&gt;. This regular reflection ensures your system stays current and that nothing falls through the cracks. During your review, spend at least 30 minutes going through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your &lt;strong&gt;Calendar&lt;/strong&gt; for upcoming events.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Next Actions&lt;/strong&gt; list to ensure tasks are still relevant.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;Projects&lt;/strong&gt; to confirm each one has a next action.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Waiting For&lt;/strong&gt; list to track delegated tasks.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;Someday/Maybe&lt;/strong&gt; list to see if anything can move into active work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By keeping your system maintained through weekly reviews, you’ll always know what to do next and feel in control of your workload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Tools
&lt;/h2&gt;

&lt;p&gt;Two more tools can enhance your GTD system:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tickler File&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is for items you need to be reminded of on specific dates but don’t belong on the Calendar, like tickets or reminders to clean your devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read/Review Folder&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Use this to store documents or articles you intend to read when you have time, turning idle moments into productive reading sessions.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  In Summary
&lt;/h2&gt;

&lt;p&gt;GTD is more than a task management system—it’s a way to clear your mind, reduce stress, and get things done efficiently. By capturing everything into a trusted system, clarifying and organising tasks, and reflecting regularly, you create space for productive thinking and purposeful action.&lt;/p&gt;

&lt;p&gt;Take it one step at a time, and soon you’ll be managing your tasks with ease, focusing on what really matters.&lt;/p&gt;




&lt;p&gt;For a more detailed guide and helpful insights into GTD, you can also refer to &lt;a href="https://hamberg.no/gtd/" rel="noopener noreferrer"&gt;this article&lt;/a&gt;, which offers a distilled version of the system and can help deepen your understanding.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Database Connection Pooling</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Sat, 24 Aug 2024 17:20:14 +0000</pubDate>
      <link>https://dev.to/siddharth_g/understanding-database-connection-pooling-420n</link>
      <guid>https://dev.to/siddharth_g/understanding-database-connection-pooling-420n</guid>
      <description>&lt;h2&gt;
  
  
  What is a Connection?
&lt;/h2&gt;

&lt;p&gt;A connection is a link between two systems that allows them to exchange information. This exchange happens as a sequence of bytes, which can be transmitted over various protocols like TCP/IP. Connections are fundamental for communication between systems, such as a web browser connecting to a web server or an application server connecting to a database.&lt;/p&gt;

&lt;p&gt;Usually, network ports are involved in establishing these connections, enabling two systems to communicate effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Database Connections Work
&lt;/h2&gt;

&lt;p&gt;When a client application needs to interact with a database, it must establish a connection. This process involves several steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;DNS Lookup&lt;/strong&gt;: Resolving the database server’s IP address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TCP Handshake&lt;/strong&gt;: Establishing a TCP connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TLS Handshake&lt;/strong&gt;: Enabling encryption for secure communication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Setup&lt;/strong&gt;: Exchanging preferences and requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Verifying the client’s identity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorization&lt;/strong&gt;: Checking the client’s permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Execution&lt;/strong&gt;: Performing the actual database query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teardown&lt;/strong&gt;: Closing the session and connection.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How Does the Number of Connections Affect Database Server Resources?
&lt;/h3&gt;

&lt;p&gt;The number of connections can significantly impact database server resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memory Usage&lt;/strong&gt;: Each connection consumes memory. For example, in PostgreSQL, each connection can use between 1.5 to 14.5 MB of memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU Usage&lt;/strong&gt;: Managing multiple connections increases CPU usage as the server has to maintain the state of each connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Contention&lt;/strong&gt;: High numbers of connections can lead to resource contention, where the server struggles to allocate resources efficiently, potentially leading to slower performance and increased latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Does the Number of Connections Affect Client Applications?
&lt;/h3&gt;

&lt;p&gt;The number of connections also affects client applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Connection Limits&lt;/strong&gt;: Database servers have a maximum number of connections they can handle. When this limit is reached, additional connection requests are rejected, leading to potential failures in client applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retry Logic&lt;/strong&gt;: Clients need to implement logic to handle connection failures, often using exponential backoff algorithms to retry connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Impact&lt;/strong&gt;: If connections are not managed efficiently, clients may experience increased latency and slower response times, affecting the overall user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Database Connection Pooling?
&lt;/h2&gt;

&lt;p&gt;Database connection pooling is a technique used to manage database connections efficiently. Instead of opening and closing a new connection for each request, a pool of connections is maintained. These connections are reused for multiple requests, which reduces the overhead of establishing new connections and improves performance.&lt;/p&gt;

&lt;p&gt;Clients (servers) don’t open connections directly with the database. Instead, they interact with a pre-created pool. The pool manages existing connections to perform required operations or create new ones as needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Connection Pooling Works
&lt;/h2&gt;

&lt;p&gt;A connection pooler manages database connections for clients by opening, closing, and maintaining them, similar to a caching system. Here’s how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Request Assessment&lt;/strong&gt;: When a client requests a connection, the pooler quickly assesses the request’s characteristics, such as the database user, operations, encryption type, and accessed database objects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connection Allocation&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reuse Existing Connection&lt;/strong&gt;: If a suitable connection is available in the pool, it is handed to the client.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create New Connection&lt;/strong&gt;: If no suitable connection exists, a new one is opened and provided to the client.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Execution&lt;/strong&gt;: The client executes its query using the allocated connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connection Reuse&lt;/strong&gt;: After the query is complete, the connection is returned to the pool for potential reuse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Garbage Collection&lt;/strong&gt;: The pooler can asynchronously remove unused connections based on criteria like time since establishment or last use.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process ensures efficient management of database connections, reducing the overhead of repeatedly opening and closing connections.&lt;/p&gt;

&lt;p&gt;By understanding and implementing database connection pooling, you can significantly enhance the performance and reliability of your applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Node.JS 22 is now available!! 🎉</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Thu, 25 Apr 2024 05:06:28 +0000</pubDate>
      <link>https://dev.to/siddharth_g/nodejs-22-is-now-available-41m7</link>
      <guid>https://dev.to/siddharth_g/nodejs-22-is-now-available-41m7</guid>
      <description>&lt;h3&gt;
  
  
  Here are few of the main updates:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;node --watch is stable ☮&lt;/li&gt;
&lt;li&gt;Browser compatible WebSocket is now enabled by default 🤙 &lt;/li&gt;
&lt;li&gt;Increased the default highWaterMark for streams. This provides a performance boost across the board at the cost of slightly higher memory usage. ⚙️&lt;/li&gt;
&lt;li&gt;Increased the default High Water Mark for streams (16KiB to 64KiB).&lt;/li&gt;
&lt;li&gt;Run package json script using node now 🙌&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g1do00m7rz03me1a0qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9g1do00m7rz03me1a0qu.png" alt="Image description" width="470" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5q51geezj4ma49hdskwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5q51geezj4ma49hdskwi.png" alt="Image description" width="800" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft87prchz6x0yivwf7wth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft87prchz6x0yivwf7wth.png" alt="Image description" width="368" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Know more about the updates and additional change-log:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en/blog/release/v22.0.0" rel="noopener noreferrer"&gt;https://nodejs.org/en/blog/release/v22.0.0&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>ActivityPub - The Protocol Decentralised Social Networking</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Wed, 25 Oct 2023 11:27:54 +0000</pubDate>
      <link>https://dev.to/siddharth_g/activitypub-the-protocol-decentralised-social-networking-3nom</link>
      <guid>https://dev.to/siddharth_g/activitypub-the-protocol-decentralised-social-networking-3nom</guid>
      <description>&lt;p&gt;This is Day 7 of my &lt;a href="https://github.com/sidgujrathi/100DaysOfScaleUp/" rel="noopener noreferrer"&gt;100-day challenge to level up&lt;/a&gt;, and today, I have explored the world of ActivityPub. I'm on a mission to explain this cool protocol and show you how it works. If you're curious about ActivityPub, you're in the right place. Let's jump right in!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fediverse
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8lctx5vld89klpgi31a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8lctx5vld89klpgi31a.png" alt="ActivityPub" width="451" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ever heard of the word 'Fediverse'? It might sound a bit complex, but it's really not. Think of it as a big playground where all the social media platforms get together and play nicely with each other.&lt;/p&gt;

&lt;p&gt;Now, you might be wondering, 'Why are we talking about the Fediverse and how does this relate to ActivityPub?' Well, for now just remember that ActivityPub is the magic that makes this whole 'Fediverse' idea possible.&lt;/p&gt;

&lt;p&gt;Lets understand all the parts in this play one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Social Media - An Universe in itself
&lt;/h2&gt;

&lt;p&gt;Fast forward to 2023, and our social media platforms have become like self-contained universes. They're bustling with activity, constantly evolving, and have developed their own unique cultures, inhabitants, rules, and characteristics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ov69puvz042m93apr5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ov69puvz042m93apr5c.png" alt="Social Media Universe" width="377" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From a technical perspective, you can think of every user as an active participant in the system, effectively serving as clients. In simpler terms, their devices, be it phones, computers, or other gadgets, act as clients.&lt;/p&gt;

&lt;p&gt;Now, when users engage in discussions, make posts, comment, or hit the like button, all these actions become activities that flow to the central server. These activities are then accessible and viewable by other users.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Need
&lt;/h2&gt;

&lt;p&gt;Alright, picture this: You're tweeting away on Twitter, while your two friends are hanging out on Facebook and Threads. Why, you ask? Well, they've got some beef with Twitter being called "X" for some reason! 😅 And you? You'd rather not jump into Mark's universe.&lt;/p&gt;

&lt;p&gt;Here's the kicker: Since you're not on their turf, you can't chat with your buddies, see their posts, drop comments, or toss them some likes – even though you really want to.&lt;/p&gt;

&lt;p&gt;You can't, why? your Twitter universe has its own unique cultures, inhabitants, rules, and characteristics and language as well and there is no way you can get or pass information to other universes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enters ActivityPub 💫 🤝
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8lctx5vld89klpgi31a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa8lctx5vld89klpgi31a.png" alt="Fediverse" width="451" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine ActivityPub as a kind of super-smart internet postman or a bridge builder. It's like the service that ensures different websites and apps can talk to each other, almost like sending emails or letters.&lt;/p&gt;

&lt;p&gt;This is basically the "go-to" way for social networks to mingle and for different platforms to shake hands. In simpler terms, if Twitter, Facebook, Threads, and others decided to hop on the ActivityPub train, all your worries about connecting with friends on various platforms would disappear.&lt;/p&gt;

&lt;p&gt;ActivityPub is like a cosmic portal where these online worlds can chat with each other and swap the info they need. It's like the grand meeting point for the digital universe. 😄&lt;/p&gt;

&lt;p&gt;And this whole setup called "&lt;em&gt;Fediverse&lt;/em&gt;"! - The "federated universe" which is decentralised social network of independent servers that can connect and communicate with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technical Jargon
&lt;/h2&gt;

&lt;p&gt;Till this point I hope I clear idea around what Activity Pub is and it's purpose.&lt;/p&gt;

&lt;p&gt;Now lets understand technically what it is?&lt;/p&gt;

&lt;p&gt;ActivityPub is an open standard protocol by &lt;a href="https://www.w3.org/TR/activitypub/" rel="noopener noreferrer"&gt;w3 Org&lt;/a&gt; that facilitates social networking and interaction between various platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Federated Servers:&lt;/strong&gt; ActivityPub relies on a network of federated servers. Each server represents a different platform or service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Activity Objects:&lt;/strong&gt; Everything you do online, from posting a cat meme to sharing your latest blog, is encapsulated as an "activity object." These objects carry information about your actions in JSON format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Followers and Actors:&lt;/strong&gt; You, as a user, are an "actor." You can follow other actors on different servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inbox and Outbox:&lt;/strong&gt; Servers have inboxes and outboxes where they receive and send activity objects. When you post something, your server sends your activity object to the followers' inboxes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delivery via HTTP:&lt;/strong&gt; Servers communicate with each other through HTTP requests, the same protocol your browser uses.&lt;/p&gt;

&lt;p&gt;Thanks to ActivityPub, activity objects can traverse server boundaries. Your posts become visible, likable, and comment-worthy to users on different platforms. It's like having a global conversation.&lt;/p&gt;

&lt;p&gt;In essence, ActivityPub shatters the barriers between online platforms, enabling users to engage seamlessly across servers. It's akin to chatting with a friend on a diverse messaging platform. ActivityPub's underlying structure empowers federated social networking, making the digital universe a more interconnected place. So, the next time you share a post or follow someone on a different platform, remember that ActivityPub is orchestrating the technical magic behind the scenes. 🌐🔍&lt;/p&gt;

</description>
      <category>fediverse</category>
      <category>socialmedia</category>
      <category>web3</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Correlation IDs: A Guide to Effective Usage</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Tue, 22 Aug 2023 11:05:18 +0000</pubDate>
      <link>https://dev.to/siddharth_g/correlation-ids-a-guide-to-effective-usage-3g9h</link>
      <guid>https://dev.to/siddharth_g/correlation-ids-a-guide-to-effective-usage-3g9h</guid>
      <description>&lt;p&gt;Have you ever had to deal with a bug or issue in a distributed system architecture (microservice architecture) or large scale scalable system where you have no idea how and where the transaction is flowing from component to component? Yes you are not alone, and it is not super complicated to solve this problem as well!&lt;/p&gt;

&lt;p&gt;Thanks to Correlation ID, a Correlation ID (Correlation Identifier) is a unique identifier assigned to a specific transaction or a sequence of related events across different components or services in a distributed system.&lt;/p&gt;

&lt;p&gt;Lets understand the problem first:&lt;/p&gt;

&lt;h1&gt;
  
  
  Problem
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrug9sjuqbp41wx4ts5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrug9sjuqbp41wx4ts5j.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets assume you are having micro service architecture for your application, and typically a API call from client comes to a MicroService and based on requirement that service is calling / executing the required actions from other MicroServices and return the result.&lt;/p&gt;

&lt;p&gt;You are also adding relevant logs for all your transactions in these API calls, now the problem is at any time you are checking these logs, you will be buried under lot of logs since there could be multiple clients are using your APIs right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o6gDSdED1B5wjC2Gc/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o6gDSdED1B5wjC2Gc/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;A Correlation ID is a unique identifier that is added to the very first interaction (incoming request) to identify the context and is passed to all components that are involved in the transaction flow. Correlation ID becomes the glue that binds the transaction together and helps to draw an overall picture of events.&lt;/p&gt;

&lt;p&gt;Assigning correlation id to each transaction or in our case API. For an HTTP Request, Correlation ID is typically passed in the header. So whenever you are initiation the API request pass the UUID as correlation id in header.&lt;/p&gt;

&lt;h3&gt;
  
  
  But how you would use it?
&lt;/h3&gt;

&lt;p&gt;So once you get this correlation id in request, you can use this to all in your logs and also forward same to next request you are forwarding to next service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Finap86sunjvnob7kxokq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Finap86sunjvnob7kxokq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way this ID becomes the glue that binds the transaction together and helps to draw an overall picture of events.&lt;/p&gt;

&lt;p&gt;It is recommended to return this same id with response as well to track a single end to end customer transaction flow through the various components.&lt;/p&gt;

&lt;h2&gt;
  
  
  In a Nutshell
&lt;/h2&gt;

&lt;p&gt;Correlation IDs might seem like a small addition, but their impact is colossal. They untangle the complexity of distributed systems, making troubleshooting feel like a well-directed movie plot rather than a wild goose chase. Embrace the Correlation ID, and watch chaos bow to the power of structured traceability.&lt;/p&gt;

&lt;p&gt;So, remember: start early, propagate consistently, log diligently, and unlock the full potential of Correlation IDs. Your future self, and your fellow developers, will thank you for the gift of clarity in the face of complexity.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Exploring Client-Server Architecture: Building Blocks of Modern Applications</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Tue, 04 Jul 2023 06:09:06 +0000</pubDate>
      <link>https://dev.to/siddharth_g/exploring-client-server-architecture-building-blocks-of-modern-applications-2jna</link>
      <guid>https://dev.to/siddharth_g/exploring-client-server-architecture-building-blocks-of-modern-applications-2jna</guid>
      <description>&lt;p&gt;In this continuously evolving world of software, one architectural style has stood the test of time and remains at the heart of modern applications: client-server architecture. Whether you're a seasoned developer or a curious enthusiast, understanding the fundamentals of client-server architecture is essential for building robust and scalable software solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Client-Server Architecture?
&lt;/h2&gt;

&lt;p&gt;Client-Server architecture is model which delivers functionality of an application into two distinct parts: the client and the server. The client represents the front-end, the user-facing component responsible for interacting with the user. It could be a web browser, a mobile app, or even a desktop application. On the other hand, the server represents the back-end, the behind-the-scenes powerhouse responsible for storing, processing, and managing data.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work then?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuoo2re1vkm2jk86vgbq9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuoo2re1vkm2jk86vgbq9.png" alt="Client Server Architecture" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The client-server architecture or model separates responsibility between clients and servers that are either within the same system or need to communicate over a network.&lt;/p&gt;

&lt;p&gt;To access services provided by Server, Client has to request the same over the network and Server will be responding with respective resources/service to client.&lt;/p&gt;

&lt;p&gt;Client will have presentation layer and can also have business layer which run GUI and business logic on received response from Server.&lt;/p&gt;

&lt;p&gt;On other hand Server will have business logic with data layer running on same machine/computer.&lt;/p&gt;

&lt;p&gt;A client-server relationship corresponds to the request-response pattern and should adhere to a standard communications protocol that defines the language and rules used for the communications. The client-server communication adheres to the TCP protocol suite.&lt;/p&gt;

&lt;p&gt;To handle business logic for the application, there are different ways the client-server architecture can be setup and handle the request response flow with business logic. Lets have a look at general types of client server architecture&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of client-server architecture
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2-Tier Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuoo2re1vkm2jk86vgbq9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuoo2re1vkm2jk86vgbq9.png" alt="2 Tier Client-Server Architecture" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 2-tier Client Server Architecture, the whole application logic is divided into 2 layers. : the client and the server. Let's take a closer look at each component and how they interact:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Client:&lt;br&gt;
The client, often a user-facing application, is responsible for presenting the user interface and handling user interactions. It can be a desktop application, a mobile app, or a web browser. The client interacts directly with the end user, gathering input and displaying output. In a 2-tier architecture, the client is also responsible for processing some of the application's business logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server:&lt;br&gt;
The server component in a 2-tier architecture is primarily responsible for data storage and retrieval. It manages the application's data and handles requests from clients. The server performs any necessary computations or business logic required to process the client's requests. The server typically connects directly to the database or file system to retrieve and update data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interaction between the client and server in a 2-tier architecture is straightforward. The client sends a request to the server, which processes the request and returns a response. The client then presents the response to the user.&lt;/p&gt;

&lt;h3&gt;
  
  
  3-Tier Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rza3ibm9ptdeif2bco7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rza3ibm9ptdeif2bco7.png" alt="3 Tier Client Server Architecture" width="800" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A 3-tier architecture divides the application into three main layers or tiers, each with its own specific responsibilities. Let's explore each tier and how they interact:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Client Tier:&lt;br&gt;
Responsible for handling the user interface and user interactions. It can be a web browser, a desktop application, or a mobile app. The primary role of this tier is to present data to the user and capture user inputs. It communicates with the middle tier to request data or perform actions based on user interactions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Middle Tier:&lt;br&gt;
The middle tier, also called the application logic tier or business logic tier, acts as an intermediary between the presentation tier and the data tier. It contains the core logic of the application, including processing user inputs, performing business rules, and coordinating data retrieval or storage operations. The middle tier receives requests from the presentation tier, processes them, and interacts with the data tier to retrieve or update data as needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data Tier:&lt;br&gt;
The data tier, also known as the backend tier, is responsible for managing data storage and retrieval. It includes databases, file systems, or any other persistent storage mechanism. The data tier receives requests from the middle tier and performs operations such as storing, retrieving, updating, or deleting data. It abstracts the underlying data storage details from the other tiers and ensures data integrity and security.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interaction between the tiers in a 3-tier architecture follows a structured flow. The presentation tier interacts with the middle tier by sending requests for data or actions. The middle tier processes these requests, applies business logic, and communicates with the data tier to fetch or store data. The data tier responds to the middle tier with the requested data or confirmation of successful data operations. The middle tier then processes the response and sends the necessary information back to the presentation tier for display or further actions.&lt;/p&gt;

&lt;h3&gt;
  
  
  N-Tier Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yz2zc5owlf2znvw4z9i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yz2zc5owlf2znvw4z9i.png" alt="N Tier Architecture" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;N-tier architecture, also known as multi-tier architecture, is a flexible and scalable model for designing software applications. It divides the application into multiple tiers or layers, each with distinct responsibilities and functions.&lt;/p&gt;

&lt;p&gt;It structure on top of same 3-tier architecture where you would have Client, Server and Data tier but apart from these you will also have additional tiers. &lt;/p&gt;

&lt;p&gt;In N-tier architecture, additional tiers can be added depending on the complexity and specific requirements of the application. These tiers can include caching layers, message queues, external services, or any other components that fulfils specific functions within the application's architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Client-server architecture forms the backbone of modern applications, enabling seamless interaction between clients and servers. By understanding the collaboration and advantages of this architectural style, developers can design and build robust, scalable, and secure software systems. So, whether you're developing a web application, a mobile app, or an enterprise solution, embrace the power of client-server architecture and unlock the potential to create transformative digital experiences.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Technical Design Document: A Guide for Software Engineers</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Tue, 13 Jun 2023 04:20:31 +0000</pubDate>
      <link>https://dev.to/siddharth_g/demystifying-the-technical-design-document-a-guide-for-software-engineers-1fk1</link>
      <guid>https://dev.to/siddharth_g/demystifying-the-technical-design-document-a-guide-for-software-engineers-1fk1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As software engineers, we understand the importance of clear communication and proper planning in the development process. One essential tool that facilitates these aspects is the Technical Design Document (TDD). In this blog post, we will demystify the TDD, explaining what it is, why it is crucial, and what key elements it should include. By mastering the art of writing effective TDDs, you can streamline your development process, foster collaboration, and ensure successful project outcomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Technical Design Document?
&lt;/h2&gt;

&lt;p&gt;A Technical Design Document (TDD), also known as a Design Specification or Design Blueprint, is a comprehensive document that outlines the architectural and technical aspects of a software system. It serves as a roadmap for the development team, providing a clear understanding of the system's design, components, and interactions. The TDD acts as a communication bridge between stakeholders, designers, developers, and testers, ensuring a shared understanding of the system's requirements and implementation details.&lt;/p&gt;

&lt;p&gt;Key Elements of a Technical Design Document&lt;/p&gt;

&lt;h4&gt;
  
  
  Introduction:
&lt;/h4&gt;

&lt;p&gt;The TDD should begin with an overview of the system, its purpose, and the business or user problems it aims to solve. It should also define the target audience and stakeholders involved in the project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Design Goals and Constraints:
&lt;/h4&gt;

&lt;p&gt;Specify the design goals and any constraints that may impact the system's architecture and implementation. This section helps align the team's understanding of the project objectives and sets the context for the design decisions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Architectural Overview:
&lt;/h4&gt;

&lt;p&gt;Provide a high-level architectural overview of the system, describing its major components and their interactions. This section should highlight the system's overall structure, including key modules, layers, and subsystems.&lt;/p&gt;

&lt;h4&gt;
  
  
  Functional Requirements:
&lt;/h4&gt;

&lt;p&gt;List and describe the functional requirements of the system, focusing on the features and capabilities it should provide. Clearly define the inputs, outputs, and behaviours expected from each functionality.&lt;/p&gt;

&lt;h4&gt;
  
  
  Non-Functional Requirements:
&lt;/h4&gt;

&lt;p&gt;Document the non-functional requirements, such as performance, scalability, security, and reliability aspects of the system. Specify any specific constraints or standards that need to be followed during the design and implementation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Data Design:
&lt;/h4&gt;

&lt;p&gt;Outline the data model and database design considerations. Describe the database schema, entity relationships, and any data migration or storage requirements. This section should also cover data access patterns and caching strategies.&lt;/p&gt;

&lt;h4&gt;
  
  
  System Components and Modules:
&lt;/h4&gt;

&lt;p&gt;Detail the individual components and modules that make up the system. Explain their responsibilities, interfaces, and dependencies. Use diagrams, such as class diagrams or component diagrams, to visualize the system's structure.&lt;/p&gt;

&lt;h4&gt;
  
  
  APIs and Interfaces:
&lt;/h4&gt;

&lt;p&gt;If the system provides APIs or interacts with external services, outline the APIs' specifications, including input parameters, return types, and error handling mechanisms. Specify any communication protocols or standards to be used.&lt;/p&gt;

&lt;h4&gt;
  
  
  Algorithms and Design Patterns:
&lt;/h4&gt;

&lt;p&gt;Describe any specific algorithms, algorithms, or design patterns that are relevant to the system's implementation. Explain the rationale behind their selection and how they address the system's requirements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Error Handling and Exception Management:
&lt;/h4&gt;

&lt;p&gt;Address how the system will handle errors and exceptions, including error codes, error logging, and recovery mechanisms. Detail the strategies for handling unexpected scenarios and ensuring robustness.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing and Quality Assurance:
&lt;/h4&gt;

&lt;p&gt;Outline the testing approach and quality assurance measures to be taken. Describe the test cases, test scenarios, and any automation frameworks or tools to be used for testing. Specify the performance and security testing requirements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deployment and Release Strategy:
&lt;/h4&gt;

&lt;p&gt;Discuss the deployment strategy, including the environment setup, configuration management, and version control. Document the steps involved in deploying the system to various environments and the release process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, mastering the art of writing a comprehensive Technical Design Document is a crucial skill for software engineers. &lt;/p&gt;

&lt;p&gt;This document serves as a blueprint for the development process, fostering effective communication, collaboration, and efficient implementation. By including key elements such as design goals, architectural overview, requirements, data design, system components, APIs, algorithms, testing, and deployment strategy, software engineers can ensure a shared understanding among stakeholders and guide the development team towards success. &lt;/p&gt;

&lt;p&gt;Embracing the power of the Technical Design Document empowers software engineers to create robust and scalable software systems that meet the desired objectives. So, invest time and effort in crafting well-structured and informative TDDs, and witness the positive impact it brings to your projects. &lt;/p&gt;

&lt;p&gt;Happy designing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Engineering Handbook: Exploring Software Architecture and Development</title>
      <dc:creator>Siddharth Gujrathi</dc:creator>
      <pubDate>Tue, 13 Jun 2023 04:11:12 +0000</pubDate>
      <link>https://dev.to/siddharth_g/the-engineering-handbook-exploring-software-architecture-and-development-5bln</link>
      <guid>https://dev.to/siddharth_g/the-engineering-handbook-exploring-software-architecture-and-development-5bln</guid>
      <description>&lt;p&gt;Welcome to The Engineering Handbook, a platform dedicated to exploring software architecture and development. As a Software Technical Architect, I will share insights and experiences in Software Designing, Solution Designing, and Development. &lt;/p&gt;

&lt;p&gt;From understanding software architecture and design patterns to scalability, performance, security, and solution governance, this blog provides valuable knowledge and practical guidance. Discover the principles, methodologies, and best practices to enhance your skills in shaping robust software systems. &lt;/p&gt;

&lt;p&gt;Join me on this journey of mastering the art of software architecture and development.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwareengineering</category>
      <category>design</category>
    </item>
  </channel>
</rss>
