How to Pass Data Through Middleware in Express JS

Поділитися
Вставка
  • Опубліковано 12 лис 2024
  • Learn how to pass data through middleware functions in Express JS with this quick and easy tutorial.
    Resources:
    -----------------
    Source code: github.com/nax...
    res.locals docs: expressjs.com/...
    Code w/ Node: www.devsprout....
    -----------------
    Thumbnail Background Photo by Markus Spiske on Unsplash

КОМЕНТАРІ • 27

  • @samantharivera-vi6gp
    @samantharivera-vi6gp Рік тому +1

    This tutorial is wonderful. You really do a great job of explaining concepts and simplifying it even for beginners. Thank you!

  • @aimeewildstone4602
    @aimeewildstone4602 3 роки тому +1

    I'm an Express beginner and this tutorial was wonderful! Great job explaining the concepts and thank you!

  • @grigoryegorov2036
    @grigoryegorov2036 4 роки тому

    Thanks! I've been struggling with an Express project with relatively complex MVC structure and res.locals saved me!

  • @webscrapping9179
    @webscrapping9179 2 роки тому +1

    saved my life man :)

  • @user-ul2mw6fu2e
    @user-ul2mw6fu2e 3 роки тому +1

    i have a questuon.i have 2 route
    FIRST
    app.get('/user',(req,res){
    req.user '' i want req.user to send second route
    })
    SECOND
    app.put('/product'(req,res){
    i want to use here
    }
    )
    how can i do this

  • @piyushwaghela5704
    @piyushwaghela5704 25 днів тому +1

    thannkss you saved my time

  • @femioyedele8097
    @femioyedele8097 3 роки тому +2

    Saved me. Thanks

  • @slimyelow
    @slimyelow 4 роки тому +1

    Really great tutorial. Make more of these please!

  • @unanimous8510
    @unanimous8510 4 роки тому +1

    Hey Ian, why for the Post.findById(req.params.id) you use 'id' and for the if statement post.author._id you use '_id'? What is the difference between id and _id? Thanks in advance.

    • @slimyelow
      @slimyelow 4 роки тому

      _id is the format for mongoDB.

  • @Layce17
    @Layce17 3 роки тому +1

    Really nice ! Was looking exactly for that :D

  • @DaggieBlanqx
    @DaggieBlanqx 4 роки тому +1

    Wow! Thank you, sir. You and Traversy Media have been helpful.I've just subscribe to you.

  • @user-ul2mw6fu2e
    @user-ul2mw6fu2e 3 роки тому +1

    thanks for video

  • @lera4135
    @lera4135 2 роки тому +1

    thank you!!!

  • @Nanda-ho5eh
    @Nanda-ho5eh 3 роки тому +1

    awsm !

  • @MathijsGroothuis
    @MathijsGroothuis 5 років тому

    How would this relate to the "put" route of an edit where I currently still use the mongoose method "findByIdAndUpdate"?

    • @DevSprout
      @DevSprout  5 років тому

      You could edit the object properties directly, then save the updated object back into the database, thus eliminating the need to find and update with the findByIdAndUpdate method.
      You can probably use the spread operator to update the found post object with the data from req.body (just a thought, it would need testing).

  • @Brian-dd2df
    @Brian-dd2df 5 років тому

    Hey Ian, I'm using express-handlebars for a project. Is there a way to modify the res.locals or app.locals object from the client side? My goal is conditionally render html based off of form selection options.

    • @DevSprout
      @DevSprout  5 років тому +1

      best bet is likely to use client side js for the dynamic html rendering, handlebars will render one time during initial request, that's it. IF you need backend data that's not available during first request/page load then use AJAX to fetch that data (via client side js script)

    • @Brian-dd2df
      @Brian-dd2df 5 років тому

      @@DevSproutthat was what I thought I needed to do, but I wasn't really sure if I could rely on modifying res.locals or app.locals without a GET or POST request. Thanks for the response, appreciate it!

  • @kid_kulafu_1727
    @kid_kulafu_1727 4 роки тому +1

    i love you remember that!

  • @JosephChambers
    @JosephChambers 5 років тому +2

    amazing.

  • @banhmibateruoc1511
    @banhmibateruoc1511 3 роки тому +1

    great

  • @juliarnasution8492
    @juliarnasution8492 4 роки тому

    thanks

  • @Lolo5
    @Lolo5 4 роки тому +1

    thanks