title: Node.js - Using a for loop in Express.js to achieve multi-language/region support
body: <p>I'm new to Node.js and I'm still not that familiar with it and I wanted to make my website support multiple regions; e.g United Kingdom and the United States.</p>
  <p>Similarly to other websites, I'd like to separate the regions in pages like <code>https://website.com/us</code> and <code>https://website.com/gb</code> and of course, a page for worldwide view or whatever you would like to call it - <code>https://website.com</code>.</p>
  <p>To do this, I came up with the idea to loop through an array with region codes and let Node.js set the page with the data it receives from each loop.</p>
  <pre><code>ar locals = ['', 'gb', 'us']; // An array with region codes
  
  ...
  
  for (var i = 0; i &lt; locals.length; i++) { // Loops through the array
      switch (locals[i]) { // A switch statement that sets up the data
          case '': // Default view (https://website.com)
              var lang = &quot;en&quot;;
              var title = &quot;&quot;;
              var href= &quot;&quot;;
              break;
          case 'gb':
              var lang = &quot;en&quot;;
              var title = &quot; (United Kingdom)&quot;;
              var href = &quot;gb/&quot;;
              break;
          case 'us':
              var lang = &quot;en&quot;;
              var title = &quot; (United States)&quot;;
              var href = &quot;us/&quot;;
      }
  
      app.get(&quot;/&quot; + href, function(request, response) {
          response.write(&quot;&lt;!DOCTYPE HTML&gt;&quot;);
          response.write(&quot;&lt;html lang=\&quot;&quot; + lang + &quot;\&quot;&gt;&quot;);
          response.write(&quot;&lt;head&gt;&quot;);
          response.write(&quot;&lt;base href=\&quot;&quot; + base + &quot;\&quot;/&gt;&quot;);
          response.write(&quot;&lt;title&gt;Nemalp&quot; + title + &quot;&lt;/title&gt;&quot;);
          ... // There are scripts below that check the html tag's lang attribute and sets up the language properly.
      });
  };
  </code></pre>
  <p>So what's the problem? Well, the page seems to be in a loading state forever. It does load <strong>some</strong> of the content but it always ends up with an <code>GET ... net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)</code> error. Not all scripts or favicons load properly at times and my gut is telling me that what I just did would get me fired everywhere, haha... It also always loads with the United States region settings...
  Where is my mistake? How do I achieve my goal properly? Any kind of help or advice is highly appreciated!</p>