In a large application, It's not practical to have all your routes in a single file. NodeJS make making modules easy with built in methods that makes it easy to import and output content. The require statement let's you import one document into another one and module.exports allows you to export the contents of a module. Within express, the use method allows our application to use external routes as part of the application. In order for external routes to work, we'll need to a router object provided by the express library to create an instance of a route. This makes the route mountable by our original application.
- [Voiceover] In a large application,…it's not practical to have all…of your routes in a single file.…So let's take a look at how we can modularize our routes…by placing them into separate documents.…NodeJS makes it super simple to build modules…with built-in methods that let you…import and output content.…So for example, the require statement…lets you import one document into another…and module.exports allows you…to export the contents of a module.…Within Express, the use method allows our application…to use external routes as part of the application.…
Now in order for routes to work,…we'll need to use a router object…provided by the Express library…to create an instance of the route.…This makes the route mountable by our original application,…but what if you have to pass data…from your application to the individual modules?…The set method of your app can create variables…that then can be passed to your routes.…That information can be passed along…to your modules through the request object…that is going to be generated when you call the application.…
In this course, Ray Villalobos walks through the process of creating full-featured websites with these technologies. First, find out how to install each package and leverage Node.js features from within Express. Then learn how to build a basic application with templating engines like EJS; create more flexible, modular code with includes and conditional statements; build APIs to manage HTTP requests to add and delete content dynamically; and configure more complex routing. Along the way, Ray implements features like customer feedback forms and real-time live chat, so you can see exactly what Node.js and Express are capable of.
- Handling HTTP requests with Node.js and Express
- Creating and modularizing routes
- Using templates
- Building flexible views
- Creating an API route
- Dealing with POST and DELETE requests
- Creating live chat features with Socket.IO