Try adding the following route as the last route:
app.use(function(req, res) { res.redirect('/'); });
Edit:
After a little research, I came to the conclusion that it is better to use app.get instead of app.use :
app.get('*', function(req, res) { res.redirect('/'); });
because app.use handles all HTTP methods ( GET , POST , etc.) and you probably don't want the undefined POST request redirected to the index page.
source share