title: Route parameters in Express JS
body: <p>I am using Express JS to handle a route <code>http://localhost:3000/location</code> which allows a mix of parameters and fixed endpoints. For example:</p>
  
  <p><code>http://localhost:3000/location</code> is the root for the route, which renders a view for a list of locations.</p>
  
  <p><code>http://localhost:3000/location/map</code> renders a view for a list of the locations drawn on a web map.</p>
  
  <p><code>http://localhost:3000/location/:id</code> contains a parameter for the ID of a location given in the URL and when called, renders a view for the details of the given location that comes from a database query.</p>
  
  <pre><code>'use strict';
  
  var path = require('path');
  var express = require('express');
  var router = express.Router();
  
  /* GET route root page. */
  router.get('/', function(req, res, next) {
    // DO SOMETHING
  });
  
  /* GET the map page */
  router.get('/map', function(req, res, next) {
    // DO SOMETHING
  });
  
  /* GET individual location. */
  router.get('/:id', function(req, res, next) {
    // DO SOMETHING
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Is this a best practise for handling a route with mixed fixed values and parameterized parameters?</p>
  
  <p>More specifically, how to properly handle the problem that when I called "<a href="http://localhost:3000/location/SOMETHINGWRONG" rel="nofollow noreferrer">http://localhost:3000/location/SOMETHINGWRONG</a>", for example, <code>http://localhost:3000/location/:id</code> was triggered which led to a database query error because "SOMETHINGWRONG" was not an integer and could not pass?</p>