There are many ways middleware can be used within an application. Scott shares a code example that demonstrates a few of these ways. He also compares third party middleware with middleware created within the application.
- [Scott] So here's some more examples of like,…different ways to use it.…So here's one piece of middleware…that I highly recommend you take note of.…You will be using it probably in the next step.…Morgan. Morgan will log all the requests…in the terminal as they come in.…So that's a third-party middleware.…We MPM install it, and then we require it.…Here's an arbitrary piece of middleware called checkAuth.…And we made it, you know we made it…because it's a ./ in front of it.…That means it's coming from our files.…And this is a piece of middleware that we made.…
So we globally set up Morgan, app.use…And then here's an example of like,…actually placing middleware on the route itself.…So you can also do that. So this is application level.…This is like a route level.…Not exactly router level, again it's a router level,…but this is like a route level.…So when I do a get request '/todos,…first run this middleware and see what it does.…This middleware can respond back to the client…with like a 401 unauthorized sorry,…or it can say, "oh yeah, you're good.…
This course was created by Frontend Masters. It was originally released on 12/30/2015. We're pleased to host this training in our library.
- Executing Node.js
- Using Express
- What is middleware?
- Testing in Node.js
- Using Mongo with Node.js
- Data modeling
- Querying data with Mongoose
- Identifying sensitive routes
- Configuring the deployment
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
2. REST APIs
5. Organization and Configuration
7. Data Modeling
10. Securing Routes
- 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.