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...

ความคิดเห็น • 105

  • @a2902793
    @a2902793 4 ปีที่แล้ว +41

    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!

  • @olaleykhan
    @olaleykhan 3 ปีที่แล้ว +11

    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.

  • @markrolandeugenio1177
    @markrolandeugenio1177 ปีที่แล้ว +1

    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.

  • @oliviabiswas9783
    @oliviabiswas9783 3 ปีที่แล้ว +2

    Never watched a tutorial so simple and clear, but also talks about the execution order. Really helpful for newbies🔥👍

  • @LoneWolf-ey1hq
    @LoneWolf-ey1hq ปีที่แล้ว

    Wow! what a mind-blowing explanation. Now I can say that middleware is just a piece of cake to me.

  • @SiddhanthPRao
    @SiddhanthPRao 4 ปีที่แล้ว +6

    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

    • @idopshik
      @idopshik 4 ปีที่แล้ว

      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?"

  • @excessreactant9045
    @excessreactant9045 ปีที่แล้ว

    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

  • @davedurkee8853
    @davedurkee8853 4 ปีที่แล้ว +1

    Simply illustrated, and finally, functions executed in order. 100%. Great video

  • @kadidibwa968
    @kadidibwa968 ปีที่แล้ว

    Excellently explained.... You're a great teacher.

  • @jeremytan3003
    @jeremytan3003 4 ปีที่แล้ว

    Excellent excellent excellent video! Been trying to find a good explanation of middleware the whole day. Finally understood when I watched your video

  • @taimoordon
    @taimoordon 4 ปีที่แล้ว +2

    Your browser list is longer than my grocery list :)

  • @claystation6360
    @claystation6360 4 ปีที่แล้ว

    When I make it this year, I'm going to be sending you donations. You are seriously the man. So grateful.

  • @rohanjain4238
    @rohanjain4238 4 ปีที่แล้ว +1

    I cant describe in words how good this is

  • @CodingJourney
    @CodingJourney 4 ปีที่แล้ว +9

    Amazing explanation! Thank you!! 🙏🙂

  • @prafullsingh37
    @prafullsingh37 3 ปีที่แล้ว

    You are my full stack guru.Whether it is react, react-native,node,express, Javascript .

  • @lichuan172
    @lichuan172 3 ปีที่แล้ว

    Best express tutorial I saw

  • @manuelhinojosa6942
    @manuelhinojosa6942 3 ปีที่แล้ว

    Thanks for this explanation. It’s so clear.

  • @meeka5041
    @meeka5041 ปีที่แล้ว

    Such a soothing voice!

  • @rashiddev7545
    @rashiddev7545 2 ปีที่แล้ว

    I don't which is more amazin, your Voice or your Tutorial?!

  • @bnssoftware3292
    @bnssoftware3292 ปีที่แล้ว

    Absolutely amazing video. Love your style of teaching. Keep them coming!

    • @bnssoftware3292
      @bnssoftware3292 ปีที่แล้ว

      And I appreciate being able to see it on mobile.

  • @anshujalan
    @anshujalan 4 ปีที่แล้ว +1

    This is some serious high quality material! Thanks a lot!

  • @ahmadnemer6148
    @ahmadnemer6148 2 ปีที่แล้ว

    this was really helpful, thanks, keep up this great work

  • @objectObject212
    @objectObject212 4 ปีที่แล้ว +1

    Great video, big thx! Your excellent teaching skills makes all clear and easy 😉

  • @aakashshrivastava9351
    @aakashshrivastava9351 4 ปีที่แล้ว

    That's the way to explain something. Hats off to you sensei!

  • @DavidMerinos
    @DavidMerinos 3 ปีที่แล้ว

    Quick and simple, thanks!

  • @phil_ka
    @phil_ka 3 ปีที่แล้ว

    Loved the way u illustrated these👌👌

  • @kal1nas
    @kal1nas 3 ปีที่แล้ว

    Thank you for the video, very clear and straight to the point, liked and subscribed

  • @dawid_dahl
    @dawid_dahl 4 ปีที่แล้ว +2

    You’re an amazing teacher! Thank you! 👏🏻👌🏻

  • @imanqoly
    @imanqoly 2 ปีที่แล้ว

    I wish I've seen this series before many headaches

  • @goodsamaritan208
    @goodsamaritan208 3 ปีที่แล้ว

    Thank you. I finally understand middleware. Subscribed!

  • @abimanoharan2378
    @abimanoharan2378 ปีที่แล้ว

    incredibly helpful. Thank you.

  • @jahongirbozarov3135
    @jahongirbozarov3135 4 ปีที่แล้ว

    Steve, the way you explained is the Best! Thanks

  • @gurpyardandiwal7963
    @gurpyardandiwal7963 ปีที่แล้ว

    amazing explanation sir love from india ❤

  • @dkevin1553
    @dkevin1553 3 ปีที่แล้ว

    Oh God... What a wonderful definition man. Great, Do More Videos on JavaScript Brother 💖

  • @csrescued1299
    @csrescued1299 4 ปีที่แล้ว

    Thank you very much @steve for this video, it has cleared my understanding in middleware portion ...thanks a lot man...😃😃🤝🤝

  • @ArpanNeupaneProductions
    @ArpanNeupaneProductions 3 ปีที่แล้ว

    Great explanation!!

  • @starterdev
    @starterdev 3 ปีที่แล้ว

    Best Tutorial Thanks! :D

  • @lovenangelodayola1826
    @lovenangelodayola1826 ปีที่แล้ว

    great explaining the concept

  • @SaurabhMehta96
    @SaurabhMehta96 4 ปีที่แล้ว

    amazing explanation! thanks for doing this! the explanation is so clear!

  • @Jore__
    @Jore__ 4 ปีที่แล้ว

    What a perfect explanation! Thank you!

  • @Daniel-nb3kk
    @Daniel-nb3kk 4 ปีที่แล้ว

    Best explanation so far.

  • @jjggtz7349
    @jjggtz7349 4 ปีที่แล้ว +1

    Subscribed, great content Steve!

  • @suemendez5674
    @suemendez5674 4 ปีที่แล้ว

    Thanks, good teacher.

  • @sagarsagar3456
    @sagarsagar3456 2 ปีที่แล้ว

    Thanks it really helped me today

  • @robinmoffatt4988
    @robinmoffatt4988 2 ปีที่แล้ว

    Nice vid! very informative :)

  • @shashikantyadav4599
    @shashikantyadav4599 3 ปีที่แล้ว

    clear explanation.

  • @corey795
    @corey795 ปีที่แล้ว

    Brilliant, thanks!

  • @hekoriginaljni6489
    @hekoriginaljni6489 4 ปีที่แล้ว +1

    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

  • @kiranthapa8067
    @kiranthapa8067 4 ปีที่แล้ว

    Great explanation!
    Thank you so much.

  • @ibadshaikh2215
    @ibadshaikh2215 4 ปีที่แล้ว

    Great explanation...finally i got it

  • @DiscipleW
    @DiscipleW 4 ปีที่แล้ว

    Excellent presentation!

  • @shivarammuthukumaraswamy7164
    @shivarammuthukumaraswamy7164 4 ปีที่แล้ว

    omg this was crystal clear..thank you so muchhhhhh.

  • @stuknowlton477
    @stuknowlton477 3 ปีที่แล้ว

    Great video!!

  • @sayeddileri3461
    @sayeddileri3461 9 หลายเดือนก่อน

    thank you sir!!

  • @UtkarshShrivastava6009
    @UtkarshShrivastava6009 4 ปีที่แล้ว

    Great explanation! Thanks!

  • @xphpxmysql
    @xphpxmysql 4 ปีที่แล้ว

    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.

  • @janaelmourad9681
    @janaelmourad9681 2 ปีที่แล้ว

    amazing thank you!

  • @dzentsetsu5607
    @dzentsetsu5607 3 ปีที่แล้ว

    Thank you!

  • @JS-zm5se
    @JS-zm5se 3 ปีที่แล้ว

    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.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      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.

  • @mikaeldv1541
    @mikaeldv1541 4 ปีที่แล้ว

    merci,ça m'a beaucoup aidé

  • @IvanMithun
    @IvanMithun ปีที่แล้ว

    Thank you

  • @kengjunxian812
    @kengjunxian812 4 ปีที่แล้ว

    really great video! thank you

  • @avgsteve
    @avgsteve 4 ปีที่แล้ว

    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!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      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.

  • @juanderuiznavas6601
    @juanderuiznavas6601 4 ปีที่แล้ว

    Really useful, thanks.

  • @digitalminister5687
    @digitalminister5687 3 ปีที่แล้ว

    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!

  • @jellyfith
    @jellyfith 4 ปีที่แล้ว +1

    EZ clap. boom done; thank you.

  • @milospavlovic9512
    @milospavlovic9512 4 ปีที่แล้ว

    Thanks man

  • @vaasudhand3200
    @vaasudhand3200 4 ปีที่แล้ว

    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?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      The middleware functions need to call next( ) or the cycle ends there. Typically you will use res.send( ) as the last step.

    • @vaasudhand3200
      @vaasudhand3200 4 ปีที่แล้ว

      @@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...

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      @@vaasudhand3200 vscode intellisense doesnt read values imported from other files.
      Quokka is a paid extension that will provide that and many other things.

  • @abhinayadutta
    @abhinayadutta ปีที่แล้ว

    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?

  • @nanu180
    @nanu180 4 ปีที่แล้ว

    How to install curl in window 7 basic on vb code as you have use
    Please suggest and guide me.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      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.

  • @user-eu2ok5dm2f
    @user-eu2ok5dm2f 4 ปีที่แล้ว +1

    can you please, do Authentication and Authorization in express js.
    thank you

  • @bnssoftware3292
    @bnssoftware3292 ปีที่แล้ว

    How would you pass data from the middleware to the next function?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  ปีที่แล้ว +1

      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.

  • @modestas2890
    @modestas2890 4 ปีที่แล้ว

    awesome stuff man

  • @kamranamiraslanov1758
    @kamranamiraslanov1758 4 ปีที่แล้ว

    hi.I couldn't get a response which you have mentioned in 3:35 .Could you help me please?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      Do you get an error message? Do you have CURL installed? You can send the request from a webpage too.

  • @aniceguy2577
    @aniceguy2577 4 ปีที่แล้ว +1

    When is the next video coming up?

  • @fatimaarshad874
    @fatimaarshad874 4 ปีที่แล้ว

    how do you have two terminals, how to get two powershells side by side

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 ปีที่แล้ว

      Click the + in the shell menu to open more shells. The drop down list let's you navigate between them

    • @fatimaarshad874
      @fatimaarshad874 4 ปีที่แล้ว

      @@SteveGriffith-Prof3ssorSt3v3 i figured it out its the icon right next to the +. Your videos are great and helpful!!

  • @abhishekjawanpuria4019
    @abhishekjawanpuria4019 3 ปีที่แล้ว

    Hey how can I send some data through AJAX to my express server

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      Same way you use fetch to send it to any server. Just send it to the right URL.

    • @abhishekjawanpuria4019
      @abhishekjawanpuria4019 3 ปีที่แล้ว

      @@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

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 ปีที่แล้ว

      @@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.

  • @ahmedelgaidi
    @ahmedelgaidi 4 ปีที่แล้ว

    perfect

  • @cgraider
    @cgraider 4 ปีที่แล้ว

    your so goooood

  • @NAMRATA195
    @NAMRATA195 4 ปีที่แล้ว

    amazing lectures, but it's really getting on my nerves, you not using nodemon

  • @mikip1701
    @mikip1701 4 ปีที่แล้ว

    Thank you!