From the course: Building a Website with Node.js and Express.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Modular routes with express.Router

Modular routes with express.Router

From the course: Building a Website with Node.js and Express.js

Start my 1-month free trial

Modular routes with express.Router

- [Instructor] Now that you're an expert on routes in middlewares, let's apply that knowledge. And I also want to show you one more important feature of Express. Until now, we defined the route for all application directly in the server.js file. That's okay for smaller applications but once the application grows, this can become confusing and hard to maintain. A good practice is to group all route definitions into a file or directory structure of its own. To accomplish that, I will create a new folder routes in my root folder and in this root folder, I will create a new file index.js. Next, I will copy that route definition for slash and while I'm here, I will remove the declaration of the speakers route. We will add it to the new routing structure in a bit. And I paste now the definition into my index.js file. Now we see those red wavy lines on the app object. That's obviously because there is no app object defined…

Contents