Express JS - What the Heck is Middleware
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- This tutorial about ExpressJS explains what middleware is, how it works, and why it is actually a core part of how Express works.
Express Tutorial Full Playlist - • Quickstart with Expres...
Sample Code from the video: gist.github.co...
1. Neat step by step explanation
2. Clear and crisp audio
3. Clean screen showing only the ide
4. No chit-chatting useless information.
I give this a 200 out of 100.
Every tutorial should take this as an example, way to go man!
why does cors need ()[cors()] but sup doesnt?
This was amazing. the parts where you say "I could put it but, I don't have to" were especially helpful. just made things that used to be confusing now way clearer.
I spent hours listening to my instructor in the bootcamp about this, and only now I fully understand what's going on, I always go back to your channel for reference, some tutorials on YT tend to forget that some words they think are basic words in coding are already jargons to the beginners, thanks Steve, you make things simple for us, you're a CODE hero.
Never watched a tutorial so simple and clear, but also talks about the execution order. Really helpful for newbies🔥👍
Wow! what a mind-blowing explanation. Now I can say that middleware is just a piece of cake to me.
Excellent and In-depth Teaching. I was trying to understand middleware for so long, but your 10 min video gave me a clear understanding of it. Thanks
Like "my grandfather wore this pants, my dad wore, and as soon as I've started to wear them I've the pants! Maybe is something wrong with me?"
Really helped me understand when you said every function you use is middleware it just so happens it occurs at the end of a long list of middleware functions
Simply illustrated, and finally, functions executed in order. 100%. Great video
Excellently explained.... You're a great teacher.
Excellent excellent excellent video! Been trying to find a good explanation of middleware the whole day. Finally understood when I watched your video
Your browser list is longer than my grocery list :)
When I make it this year, I'm going to be sending you donations. You are seriously the man. So grateful.
I cant describe in words how good this is
Amazing explanation! Thank you!! 🙏🙂
You are my full stack guru.Whether it is react, react-native,node,express, Javascript .
Best express tutorial I saw
Thanks for this explanation. It’s so clear.
Such a soothing voice!
I don't which is more amazin, your Voice or your Tutorial?!
Absolutely amazing video. Love your style of teaching. Keep them coming!
And I appreciate being able to see it on mobile.
This is some serious high quality material! Thanks a lot!
this was really helpful, thanks, keep up this great work
Great video, big thx! Your excellent teaching skills makes all clear and easy 😉
That's the way to explain something. Hats off to you sensei!
Quick and simple, thanks!
Loved the way u illustrated these👌👌
Thank you for the video, very clear and straight to the point, liked and subscribed
You’re an amazing teacher! Thank you! 👏🏻👌🏻
I wish I've seen this series before many headaches
Thank you. I finally understand middleware. Subscribed!
incredibly helpful. Thank you.
Steve, the way you explained is the Best! Thanks
amazing explanation sir love from india ❤
Oh God... What a wonderful definition man. Great, Do More Videos on JavaScript Brother 💖
I have many hundreds of JS videos on my channel
Thank you very much @steve for this video, it has cleared my understanding in middleware portion ...thanks a lot man...😃😃🤝🤝
Great explanation!!
Best Tutorial Thanks! :D
great explaining the concept
amazing explanation! thanks for doing this! the explanation is so clear!
What a perfect explanation! Thank you!
Best explanation so far.
Subscribed, great content Steve!
Thanks, good teacher.
Thanks it really helped me today
Nice vid! very informative :)
clear explanation.
Brilliant, thanks!
Is it potentially possible to get stack overflow if we have too many middleware functions like we get with too many recursions? If I understand it correctly, one function just before finishing calls another function and it goes deeper and deeper and one day it may run out of memory
It would take thousands of middleware functions.
Great explanation!
Thank you so much.
Great explanation...finally i got it
Excellent presentation!
omg this was crystal clear..thank you so muchhhhhh.
Great video!!
thank you sir!!
Great explanation! Thanks!
So a middleware function is basically a function that takes a request object and either return a response to the client or passes control to another middleware function.
Pretty much. And the get( ) and post( ) methods are just middleware functions too.
amazing thank you!
Thank you!
Is it necessary to use 3 arguments (req, res, next) compulsory for any function to use as a middlewhere. If I want to use more arguments there, what I need to do?
I want to add two numbers inside a middlewhere and print the results.
Since we use app.use( ) to set up and run the middleware functions, it is the Express framework that calls the middleware functions for us. It will always pass those three things - the request, the response, and a reference to the next function in the middleware chain.
We can't force it to pass along anything else.
However, we do have access to the Request and Response objects.
We can extend those objects and add our own custom properties at each step in the process.
Those properties will be available in the next middleware function.
merci,ça m'a beaucoup aidé
Thank you
really great video! thank you
Really great explanation! As the logs seen in the terminal, I wonder if the order of executing different Middleware functions is like following?
(around 9:12)
1. app.use(sup) in app.js ===> the logs of "GET" and "sup"
2. how() in middle.js (because of the next() in sup()? ) ===> the log of "how you doin?". Then again the logs of "GET" and "sup"
3. app.use(cors()) (because of the next() in how()? )
I have this question because the order the the logs doesn't seem to be matched with same order of the parameters in app.get() like "/", how , sup then (req, res) arrow function. Thanks!
The first one is right. After that how( ) gets called from inside app.get(). Finally, sup( ) gets called from inside app.get().
The order of middleware is
1. All the global middleware functions in the order that you write them.
2. All the middleware functions inside the matching route.
3. The final (req, res)=>{} function inside the route where send( ) gets called instead of next()
If a middleware function doesn't call next( ) then the process will stop at that point.
You can use next( ) inside the final function that calls send( ) to call another function for things like a log too. As long as it doesn't try to send back data.
Really useful, thanks.
If I am using some package in the middle.js file, should I put the require() statement in middle.js or in app.js? Thanks in advance!
If middle.js needs a package then it needs to require it.
EZ clap. boom done; thank you.
Thanks man
I just have one question, Built in middleware functions like app.use(express.json()) and app.get('/', () => res.send('Hello')), Do they terminate the cycle or do they automatically invoke the next() method, to pass control to the next middleware function?
The middleware functions need to call next( ) or the cycle ends there. Typically you will use res.send( ) as the last step.
@@SteveGriffith-Prof3ssorSt3v3 Also, why dosen't intellisense work in the middle.js file. It doesn't show any methods or properties related to req or res parameter...
@@vaasudhand3200 vscode intellisense doesnt read values imported from other files.
Quokka is a paid extension that will provide that and many other things.
This video is just awesome. Cleared the concept in minutes. I've been getting finahandler 404 error in an express.js module. Not sure how to handle that. Any pointers?
I don't know what a finahandler is.
How to install curl in window 7 basic on vb code as you have use
Please suggest and guide me.
There are tons of resources online for how to install CURL on windows. Once it is installed then you can use it in any terminal command window.
can you please, do Authentication and Authorization in express js.
thank you
Coming in the near future.
How would you pass data from the middleware to the next function?
Middleware functions get the request, the response, and the next objects passed to them.
If you want to pass data along the chain then just add it to the request object. As a JavaScript object you can add any properties that you want.
awesome stuff man
hi.I couldn't get a response which you have mentioned in 3:35 .Could you help me please?
Do you get an error message? Do you have CURL installed? You can send the request from a webpage too.
When is the next video coming up?
Tomorrow
how do you have two terminals, how to get two powershells side by side
Click the + in the shell menu to open more shells. The drop down list let's you navigate between them
@@SteveGriffith-Prof3ssorSt3v3 i figured it out its the icon right next to the +. Your videos are great and helpful!!
Hey how can I send some data through AJAX to my express server
Same way you use fetch to send it to any server. Just send it to the right URL.
@@SteveGriffith-Prof3ssorSt3v3 I tried to add some data in xhr.send("") using a post method but in my express server if Im doing console.log(req.body) Im getting an empty object after making the request
@@abhishekjawanpuria4019 It's going to depend on the headers that you set and the formatting of the data that you send.
This is why I stopped using xhr and switched to fetch years ago. Much better security and control over data.
I've got a playlist on AJAX with lots of videos on fetch and how to format and upload data.
perfect
your so goooood
amazing lectures, but it's really getting on my nerves, you not using nodemon
In some videos I do
Thank you!