Alvin Alvin - 3 months ago 12
Node.js Question

why get is always hitting the first route

I am using express.

I have 2 routes:

router.get('/:id', function (req, res, next) {

router.get('/search', function (req, res, next) {

Every time I call GET
I hit the fist route instead of the second one?

What should I change?


Because /:id matches anything include /search. It thinks the id is 'search'. Try putting the '/search' route first, or change it to /find/:id.