I encountered an error while trying to develop an API for a travel company. The error message "TypeError: Cannot create property 'next' on string '/:id'" keeps popping up, even though all the necessary functions are already created.
const express = require('express');
const port = 3000
const app = express();
const tourRouter = express.Router();
tourRouter.route('/').
get(getAllTours)
.post(createTour);
tourRouter('/:id').
get(getTour)
.patch(updateTour)
.delete(deleteTour);
app.use('/api/v1/tours', tourRouter)
app.listen(port)
The specific error is:
req.next = next; ^
TypeError: Cannot create property 'next' on string '/:id'
at Function.handle (C:\Users\dell\OneDrive\Desktop\node\starter\node_modules\express\lib\router\index.js:160:12)
at router