here's my code for setting up PATCH request in node.js
app.patch('/api/v1/tours/:id', (req, res) => {
const id = req.params.id * 1;
const tour = tours.find(tour => tour.id === id);
if (!tour) {
return res.status(404).json({
status: 'fail',
message: 'Invalid ID'
});
}
const updatedTour = {...tour, ...req.body};
const updatedTours = tours.map(tour => tour.id===updatedTour.id ? updatedTour : tour);
fs.writeFile(`${__dirname}/dev-data/data/tours-simple.json`,
JSON.stringify(tours),
err => {
res.status(200).json({
status: 'success',
data : updatedTour
});
})
});
But when I did the patch request and clicked send in Postman, it didn't work at all patch url
Could someone help me with this? I checked every syntax and common slashes error in the URL but everything was fine. I'm using Express.js for this.