title: Express.js routing: optional splat param?
body: <p>I have a route that looks like this:</p>
  
  <pre><code>app.all('/path/:namedParam/*splat?',function(req,res,next){
    if(!req.params.length){
      // do something when there is no splat
    } else {
      // do something with splat
    }
  });
  </code></pre>
  
  <p>however, this doesn't work - if I call <code>path/foo/bar</code> it hits the route, but if I call <code>path/foo</code>, it doesn't.</p>
  
  <p>Is it possible to have an optional splat param, or do I have to use a regex to detect this?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>to be clearer, here are the requirements I'm trying to achieve:</p>
  
  <ul>
  <li>the first and second params are <strong>required</strong></li>
  <li>the first param is static, the second is a named param.</li>
  <li>any number of <em>optional</em> additional params can be appended and still hit the route.</li>
  </ul>