you can try to use "use", I did like this when I got this problem, I added it after all the routes:
app.use(req: Request, res: Response) => { res.status(404).json({ message: `The URL ${req.originalUrl} doesn't exist` }); });