title: How to get optional language parameter from URL in Express routes?
body: <p>I'm stuck with a stupid problem:
  How to work with <em>optional</em> locale parameter?</p>
  
  <p>That's what I mean:</p>
  
  <p>For example, I have <em>frontpage</em> and <em>contacts</em>, here is routes:</p>
  
  <pre><code>app.get('/', frontpage.get);
  app.get('/contacts', contacts.get);
  </code></pre>
  
  <p>Now I'm trying to add localization to my site</p>
  
  <pre><code>app.all('/:lang?*', language.all); -&gt; detect and set locale
  app.get('/:lang?', frontpage.get);
  app.get('/:lang?/contacts', contacts.get);
  </code></pre>
  
  <p>The only problem is when I don't use lang-parameter in URL:</p>
  
  <pre><code>mysite.com/contacts
  </code></pre>
  
  <p>because Express uses <strong>'contacts'</strong> as a language parameter.
  (+ I don't like this copy-pasted <code>:lang?</code>)</p>
  
  <p>I think, I just took the wrong way.</p>
  
  <p>How to use locale parameter from URL in Express?</p>
  
  <p>PS: I dont want to use subdomains <code>de.mysite.com</code> or querystring <code>mysite.com?lang=de</code>. I want exactly this variant <code>mysite.com/de</code></p>