From the course: Express Essentials: Build Powerful Web Apps with Node.js

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

What is route chaining in Express?

What is route chaining in Express?

- [Instructor] When creating routes with Express, especially with more complex projects, we may have several routes with the same path, but using different methods. Using the method route on our app, we can chain several methods together to keep our code clean and easy to understand. What might this look like? In our index JS file, I've created three routes with the same path, slash class, and they are each using a different method, get, post, and put. Let's first start by adding app.route. So, right above this, right above our route chaining in our index JS file here, I'm going to add app.route. All right, and this is going to take an argument that represents our path. So in this case, that will be class. So, make sure you have the slash class. All right. From here, all we need to do is chain our existing methods to this route. I'm going to copy everything from dot get to the end and paste this right after.…

Contents