Join Daniel Khan for an in-depth discussion in this video Creating the routes, part of Building a Website with Node.js and Express.js.
- [Instructor] In our very first basic example…we added the routes directly to a main application script.…While this is valid, today it's best practice…to move routes into dedicated files…and create modular sub-applications using express router.…By creating such sub-apps, routes are not dependent…on the overall side structure and easier to maintain,…especially when a team works on the routes.…When looking at the html side,…we already saw the different route we will need.…So we have this index page.…
Then we also have the route…that should give us a list of all speakers.…Then we will also need a speakers detail page…and a route that gives us the feedback page.…Let's create those routes now using express router.…For that, I use a pattern that I found to be very useful.…We will turn our route files into functions…that can take parameters.…By doing so, we can easily pass down information…like configuration data to all routes.…
So I am getting started by creating a folder routes…inside our server folder,…and in there, I create a file, index.js.…
Author
Released
10/29/2018- Creating a server with Express and pure Node.js
- Handling errors in Express
- Creating routes
- Using templates
- Working with the Pug template engine
- Implementing the site structure and logic
- Working with conditionals
- Dealing with POST requests
- Sanitizing user inputs and handling form errors
Skill Level Beginner
Duration
Views
Related Courses
-
Building RESTful Web APIs with Node.js and Express
with Emmanuel Henri1h 40m Intermediate -
Express Essential Training
with Emmanuel Henri1h 51m Beginner -
Node.js: Build Your First Microservice
with Daniel Khan2h 9m Intermediate -
Node.js Essential Training
with Alex Banks6h 22m Intermediate
-
Introduction
-
What you should know1m 40s
-
1. Getting Started
-
2. Express Basics
-
Handling errors in Express5m 54s
-
Working with environments3m 35s
-
3. Getting Started with Our Project
-
Reviewing the provided HTML1m 25s
-
Creating the routes8m 55s
-
Serving static files5m 4s
-
-
4. Getting Started with Templates
-
Template engines in Express2m 26s
-
Understanding Pug syntax3m 20s
-
Creating a custom error page11m 56s
-
Creating the index template2m 11s
-
-
5. Implementing the Site Structure and Logic
-
Adding central configuration3m 29s
-
Adding dynamic data15m 48s
-
Looping through data15m 59s
-
Working with conditionals11m 22s
-
6. Handling Form Data
-
Handling POST requests6m 23s
-
Storing data3m 22s
-
Conclusion
-
Using Express generator3m 32s
-
Next steps46s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Creating the routes