Express parameterized route conflict Express parameterized route conflict express express

Express parameterized route conflict


Do it like this . Dynamic api should be on bottom

router.get('/new', function(req,res){});router.get('/:id', function (req, res) {});

A very simple example with test


You need to add a function to check the parameter and place /new router before /:id:

var express = require('express'),    app = express(),    r = express.Router();r.param('id', function( req, res, next, id ) {    req.id_from_param = id;    next();});r.get("/new", function( req, res ) {  res.send('some new');});// route to trigger the capturer.get('/:id', function (req, res) {  res.send( "ID: " + req.id_from_param );})app.use(r);app.listen(3000, function () { })