I am using Express JS for backend API.
I need to simply use res object from custom service, not route controller.
Of course I am calling service function from controller and I know that I can easily pass res as an argument and access it, but I wonder if there is other case or maybe better practice.
const videoaskResponse = async (req, res, next) => {
try {
await webhookService.handleVideoaskResponse(req.body, res)
res.status(200).json({ received: true })
} catch (error) {
next(error)
}
}
Here’s example how I handle that case.