Categories
JavaScript Answers

How to add a catch all route for everything except for /login with Node.js Express?

Spread the love

To add a catch all route for everything except for /login with Node.js Express, we add the route for /login before adding the catch all route.

For instance, we write

app.get("/login", (req, res) => {
  //...
});

app.get("/", (req, res) => {
  //...
});

app.get("*", (req, res) => {
  //...
});

to add get routes for the /login and / URLs before adding the catch all route to let the higher route handlers handle requests to /login and /.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *