<?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: Darryl Daniel</title>
    <description>The latest articles on DEV Community by Darryl Daniel (@darryldaniel).</description>
    <link>https://dev.to/darryldaniel</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%2F402629%2F4659f4e3-f2e9-4c1f-8e06-739b4de41e06.jpeg</url>
      <title>DEV Community: Darryl Daniel</title>
      <link>https://dev.to/darryldaniel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darryldaniel"/>
    <language>en</language>
    <item>
      <title>How I Manage my Day</title>
      <dc:creator>Darryl Daniel</dc:creator>
      <pubDate>Sun, 16 Aug 2020 14:30:58 +0000</pubDate>
      <link>https://dev.to/darryldaniel/how-i-manage-my-day-2co4</link>
      <guid>https://dev.to/darryldaniel/how-i-manage-my-day-2co4</guid>
      <description>&lt;p&gt;&lt;em&gt;Cover image by &lt;a href="https://unsplash.com/@icons8"&gt;Icons8 Team&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/manager"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You probably have busy days. Kids, work, household chores and maintenance, finding gifts for birthdays. Time is our most valuable resource and we're expected to manage it all. In software development, this can get tricky. We're often pulled in multiple directions on a daily basis - there's a bug in production, someone needs you to review their code, there's a new feature for you to design. I find context switching (amongst other things) to be a major productivity killer. What follows are a few simple techniques I use to manage my day.&lt;/p&gt;

&lt;p&gt;I find there's generally 3 things I need out of a day manager:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The ability to reduce the effects of context switching&lt;/li&gt;
&lt;li&gt;Not missing anything important I need to remember&lt;/li&gt;
&lt;li&gt;Handle recurring and ad-hoc admin&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I've been using Notion for over a year now and I find it extremely useful. It's flexibility (although it comes with a steep learning curve) allows me to create as simple or as complex a system as I want. It's helpful to view how others have set up their systems in Notion. I recommend Marie Poulin or August Bradley's YouTube videos (links at the end). Of course, any other app (even pen and paper) would work perfectly fine here. Here's a demo of my setup in Notion:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rCmsRU_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rejm4v2dpegsrtvgcb3u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rCmsRU_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rejm4v2dpegsrtvgcb3u.png" alt="My day manager in Notion"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The task list
&lt;/h2&gt;

&lt;p&gt;Firstly, it's important at the start of your week to map out what you need to accomplish for the week and the tasks needed to get you there. This process is important and will save you a lot of time later. At the start of each day you should have a list of things that you need to get done for the day. Prioritize these as you see fit.&lt;/p&gt;

&lt;p&gt;The main benefit of having this done up front is that you don't waste time deciding what you have to do for the day. It's easy just to pick the highest priority task and do it. The added benefit is that when you're inevitably interrupted, once you've handled whatever has demanded your attention, you don't have to think about what you were doing. It's front and centre.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reminders
&lt;/h2&gt;

&lt;p&gt;I like to have a space somewhere to record things that I need to remember. This used to be sticky notes for me. Sticky notes are great. They're always visible, small enough that you don't add too much detail and colourful so it draws your attention whenever you stop focussing on a task. Recently, though, I've found myself needing them less and less.&lt;/p&gt;

&lt;p&gt;I've added an area right above my task list where I can write out things I need to remember. I can even colour code them or add a date reminder if they're really important. Like a virtual sticky note. Any time I've completed a task and I come back to my task list to see what's next, there my reminders are. I can choose whether or not to act on something.&lt;/p&gt;

&lt;p&gt;This space is particularly helpful in managing interruptions or context switching. For example, if I'm interrupted but it's not urgent, I can leave myself a reminder to handle it later. I'm free to go back to focussing on a more important task without worrying that I'll forget.&lt;/p&gt;

&lt;h2&gt;
  
  
  Admin tasks toggle
&lt;/h2&gt;

&lt;p&gt;I keep a space with admin things that I need to do but don't have a specific time frame. I put this behind a toggle so that it's out of sight. The best thing about this is that it's no longer in my face screaming that it needs to be done and I have peace of mind knowing that it won't be forgotten. When I have a break or some spare time, I can just sort out as many as I want. It's also helpful having a centralized place where I can add tasks as I see things that need to be done.&lt;/p&gt;

&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;There's  a lot more going on behind the scenes here. For example, I have a process that I utilize to plan out my entire week which lets me look at the projects that I have on the go and plan the tasks I'm going to execute on each day of the week. If I don't finish those tasks, they automatically roll over to the next day. I also have a method for handling monthly / weekly recurring tasks which I'll share in a future post. I hope this has helped in some small way to bring a little bit more order to the usual chaos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Amazing Notion resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=4-TYSah25UM&amp;amp;list=PLAl0gPKnL3V8LYdoT1Czuz6xfmZoAmSBc"&gt;August Bradley Notion life operating system&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/playlist?list=PLzaYMdbJMZW2N85S4aVENBjQBaT-P08rk"&gt;Marie Poulin Notion office hours&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>notion</category>
    </item>
    <item>
      <title>How to health check multiple PM2 processes with NGINX</title>
      <dc:creator>Darryl Daniel</dc:creator>
      <pubDate>Fri, 05 Jun 2020 13:59:46 +0000</pubDate>
      <link>https://dev.to/darryldaniel/how-to-health-check-multiple-pm2-processes-with-nginx-5gph</link>
      <guid>https://dev.to/darryldaniel/how-to-health-check-multiple-pm2-processes-with-nginx-5gph</guid>
      <description>&lt;p&gt;Production node apps require multiple instances for reliability. One possible configuration that achieves this uses PM2 to manage the app instances and lifecycle and NGINX for the load balancing. When running in this configuration, however, it can become tricky to check the health status of each instance individually.&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%2Fi%2Fhgcogekbzh4x5e28hmdn.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%2Fi%2Fhgcogekbzh4x5e28hmdn.png" alt="Example '/health' request flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the above diagram, when one of the PM2 instances has shut down, NGINX's load balancer will see that the first instance is dead and route the request to the instance that is up and running. You won't be able to check on the status of the dead instance until it is restarted and NGINX will continue to tell you that everything is fine despite one of the app instances being down.&lt;/p&gt;

&lt;p&gt;In this post, I'd like to demonstrate a method of configuring NGINX such that each instance can be checked independently and the above scenario avoided.&lt;/p&gt;

&lt;p&gt;Start with a basic node server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Koa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;koa&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;Router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@koa/router&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Koa&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;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// PM2 will set the NODE_APP_INSTANCE when it spins up an instance&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;portOffset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_APP_INSTANCE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;router&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;/health&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;healthServerNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;portOffset&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;health status server &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;healthServerNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; -&amp;gt; ok&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;router&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="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;ctx&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;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;default route&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&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="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;routes&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="mi"&gt;9001&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;portOffset&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;process.env.NODE_APP_INSTANCE&lt;/code&gt; variable is set by PM2. Each app instance will be assigned it's own port based on the value set by this variable. This will make each app instance accessible via it's own port. The PM2 config looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;health-checks-app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;script&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;max_memory_restart&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;100M&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;watch&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;log_date_format&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YYYY-MM-DD HH:mm:ss.SSS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;env&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NODE_ENV&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exec_mode&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cluster&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;instances&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;kill_timeout&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apps&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following to the NGINX config on the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;upstream&lt;/span&gt; &lt;span class="n"&gt;health_check_servers&lt;/span&gt; {
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;:&lt;span class="m"&gt;9001&lt;/span&gt;;
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;:&lt;span class="m"&gt;9002&lt;/span&gt;;
}

&lt;span class="n"&gt;upstream&lt;/span&gt; &lt;span class="n"&gt;health_check_server_1&lt;/span&gt; {
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;:&lt;span class="m"&gt;9001&lt;/span&gt;;
}

&lt;span class="n"&gt;upstream&lt;/span&gt; &lt;span class="n"&gt;health_check_server_2&lt;/span&gt; {
    &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;:&lt;span class="m"&gt;9002&lt;/span&gt;;
}

&lt;span class="n"&gt;server&lt;/span&gt; {
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;;
    &lt;span class="n"&gt;server_name&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;;

    &lt;span class="n"&gt;location&lt;/span&gt; ~ ^/&lt;span class="n"&gt;health&lt;/span&gt;/&lt;span class="n"&gt;instance&lt;/span&gt;-(.+)$ {
        &lt;span class="n"&gt;rewrite&lt;/span&gt; ^/&lt;span class="n"&gt;health&lt;/span&gt;/&lt;span class="n"&gt;instance&lt;/span&gt;-(.+)$ /&lt;span class="n"&gt;health&lt;/span&gt; &lt;span class="n"&gt;break&lt;/span&gt;;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;://&lt;span class="n"&gt;health_check_server_&lt;/span&gt;$&lt;span class="m"&gt;1&lt;/span&gt;;
    }

    &lt;span class="n"&gt;location&lt;/span&gt; / {
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;://&lt;span class="n"&gt;health_check_servers&lt;/span&gt;;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 3 separate upstream definitions. One for the pool where NGINX will pick a server for each request based on a round robin and one each for each instance. Each time a new instance is added, this will have to be updated.&lt;/p&gt;

&lt;p&gt;So how does this all fit together? When a request is made to &lt;code&gt;/health/instance-1&lt;/code&gt;, NGINX will route that request to the &lt;code&gt;health_check_server_1&lt;/code&gt; upstream which will make a request to the instance on port 9001. Likewise, when the url is &lt;code&gt;/health/instance-2&lt;/code&gt; the second instance will receive the request. The rewrite is important here otherwise the url that is requested on the app will be &lt;code&gt;http://localhost:9001/health/instance-1&lt;/code&gt; which does not exist. We rewrite this to &lt;code&gt;/health&lt;/code&gt; to get the correct endpoint.&lt;/p&gt;

&lt;p&gt;This configuration enables us check the status of each app separately. The benefit here compared to having some kind of monitoring directly on a server is that your application is tested end-to-end and you can be confident in the fact that it is accessible reliably from the outside world.&lt;/p&gt;

&lt;p&gt;Example repo can be found &lt;a href="https://github.com/darryldaniel/health-checks" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
    </item>
  </channel>
</rss>
