Alvin Alvin - 1 year ago 80
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download