Lesson 9. Routing in Express.js

 

In lesson 8, I introduced Express.js as a framework for Node.js web applications. The rest of this unit is dedicated to exploring Express.js functionality and using its convenient methods. This lesson covers routing and how a few more Express.js methods allow you to send meaningful data to the user before building a view. You also walk through the process of collecting a request’s query string. The lesson ends by touching on the MVC design pattern.

This lesson covers

  • Setting up routes for your application
  • Responding with data from another module
  • Collecting request URL parameters
  • Moving route callbacks to controllers
Consider this

You want to build a home-page view for your recipe application that people can visit to see an estimated date of completion for your application. With your new, clean Express.js setup, you’d like to keep the date variable in a separate file that you can easily change without modifying your main.js file.

After setting up your routes, you’ll be able to store some data in a separate module and respond dynamically with that data. With the separate module, you’ll be able to modify that file’s contents without needing to edit your main application file. This structure helps prevent you from making mistakes in your code while constantly changing values.

9.1. Building routes with Express.js

9.2. Analyzing request data

9.3. Using MVC

Summary

sitemap