In this video, Emmanuel Henri introduces the use of middleware in the express endpoints, and adds a few lines of code leveraging the request object.
- [Instructor] What is a middleware?…In the context of our node and express server,…how would it be used?…Middleware are simply functions…that have access to the request…and response object and our express obligation.…It can run their code there.…It can make changes to the request response objects,…can end them, can call on other function and stack…using next, etc.…Although an example on a routes with middleware…in one of the end points.…Let's get to it.…So let's go back into our routes…and use the get call to make a middleware.…
So let's go ahead…and instead of just doing a simple function…without the curly braces.…This time, we'll need to have curly braces.…So let's go ahead and do that…and let's cut the code at Line 6…like so and then paste it here at Line 4 like so.…Perfect.…So, I'm just going to add a little note here…to point out that this is the middleware.…If you want to go back to it later on,…you'll have that note there.…So let's do a console log like so,…and then let's do tablet strings like we've done earlier…
- Setting up a project and a server
- Setting up a database and schema
- Creating POST, GET, PUT, and DELETE endpoints
- Serving files
Skill Level Intermediate
1. Setting Up
2. Initial Server Build
3. CRUD Operations
4. Other API Options
Static files serving3m 16s
Next steps1m 1s
- 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.Cancel
Take 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.