How to Setup Routes with Express Router | Node.js & Express tutorials for Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024

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

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 ปีที่แล้ว +6

    As your Node & Express app grows, you will want to organize it into separate route files instead of handling everything inside of one file. The Express router lets you do this, and in this tutorial you will learn how to create individual route files for the Express router. If you are just starting with Node & Express, you may want to go to the beginning of the Node.js for Beginners playlist found here: th-cam.com/play/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw.html

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

    I've watched many NodeJS and express tutorials but the satisfaction I'm getting here, I didn't get before. It's more like I'm gaining confidence in learning the quality content. I first time watched your tutorial on free Code Camp and I decided to come over here.

  • @ahmad-murery
    @ahmad-murery 2 ปีที่แล้ว +8

    Separating routes into multiple files is great thing to consider even for small app as nobody knows how complex it can get as you work on it,
    About Thunder Client extension, it looks more like Postman inside VSCode, but at least you don't have to leave your editor for testing your API,
    unfortunately the request data is distributed in multiple places and you need to find your way through dozens of tabs to add/edit your params 😵.
    I liked the plain text way that REST Client extension is using to create requests, it keeps me aware of all the headers needed to make a successful request instead of just implementing them for me automatically,
    Looking forward for your next video, I always appreciate your way of organizing your code,
    Thanks Dave 👍

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

      Thank you Ahmad! Yes, I need to compare Thunder Client vs REST Client vs Postman. I appreciate your feedback.

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

      Cool

  • @eddiebello9547
    @eddiebello9547 7 หลายเดือนก่อน +1

    a few years late but this was very very helpful, understood everything in this video

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

    Too bad I can't give more than one like. Your teaching is excellent!

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

    Thank you so much, Dave, great tutorial

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

    It is so explained on each concept. I am waiting your advance mern stack project

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

    Thank you dave, for providing us with such great tutorial. may God bless you.

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

    Okay lets get it straight and clear these tutorials are gold.

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

    for the static css and js, I think it would be more simple to make only the root serve it and change all the js and css urls by adding a "/" at the beginning.
    "style/style.css" => "/style/style.css"
    "js/index.js" => "/js/index.js"

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

      That could work! 😀 I wanted to demonstrate how static files could be added to any specific directory though. Thanks for the comment! 💯

    • @ahmad-murery
      @ahmad-murery 2 ปีที่แล้ว +1

      @@DaveGrayTeachesCode Which might be useful in some cases where a specific route requires some additional or different static files

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

    Thanks a lot Dave !

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

    amazing tutorial

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

    Holy cow, Thunder Client is so convienient!

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

    Great tutorial!! This is awesome. I'm grateful, it helped me so much

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

    Amazing tutorial thank you

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

    This is great!

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

    I have a question: Why the object keys of the sent data must have " ". Can't they be without " " ? On React for example when I make a PUT request using the fetch() function, the body of the request does not need the " " for the data object keys. Thank you!

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

      Good question, Laza - you did not provide a timestamp for me to reference, but if I put quotes around the property name of an object, they are likely not needed. You can see examples of Express response objects here: expressjs.com/en/4x/api.html#res.json

  • @imadbenmadi
    @imadbenmadi 10 หลายเดือนก่อน

    bro yr amaizing

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

    very nice

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

    NIce video.

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

    Im stuck on Multiple http methods per route and parameter values section.
    my req.body is empty while calling post can anyone help me

  • @sagarsunil8818
    @sagarsunil8818 6 หลายเดือนก่อน

    am getting an issue , except the get method all other methods are not responding ..its not showing any content to the body

    • @sagarsunil8818
      @sagarsunil8818 6 หลายเดือนก่อน

      help please anyone

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

    Hi, I'd like to know which other extensions you use when coding nodejs applications

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

      Hello Akbar - my extensions do not change when I'm working with Node.js or React or anything else. I do not use many. I do use the Github theme for VS Code. I should make a video on this. 💯

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

      Thanks Dave, I was referring to VS Code extensions such as Eslint, Material icon, Thunder client, etc. Are there others that you use that you find useful?

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

      I understand. I don't use many though.

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

    How to use it

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

  • @agus-wesly
    @agus-wesly ปีที่แล้ว

    when i send a post request on thunder client i just receive empty object as the response. but i already send the body same as in the video. how can i fix that?

    • @agus-wesly
      @agus-wesly ปีที่แล้ว +1

      recently back from stack overflow and i figured out that i forgot to use the express.json() middleware

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

      Glad you found the solution!

    • @harshitsz8144
      @harshitsz8144 10 หลายเดือนก่อน

      @@agus-wesly thanks, i was also facing this problem

  • @gandalfgrey91
    @gandalfgrey91 3 หลายเดือนก่อน

    I came from a background of using python and tornado, what I did was add `app.use(‘/myBaseRoute’, router.getMyBaseRoutes()` and within that file I parse the request.path and use a switch case to pass the route to the appropriate handler, the default being throwing a “route not found” error. Seems a lot cleaner to me honestly

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

    Can you provide any solution export import of express router as in es6? It'll be helpful

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

      I Googled: es6 import express router ...first result: stackoverflow.com/questions/38550979/importing-exporting-the-express-router-using-es6-import-export-keywords-and-ba

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

      @@DaveGrayTeachesCode Thank you for your support 😎

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

    Hi, Dave! I'm at 22:08 working with Thunder Client right now in VS. I selected "Send" for the local host and it's stuck on processing. Would you happen to know the reason for this? Thanks!

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

      I realized I had ONE THING misspelled. It took two hours of my life to figure that out 🙃 I appreciate your help!

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

      Just saw your comments, but yes, many times it is the little details 😀

    • @HOW-bt3et
      @HOW-bt3et หลายเดือนก่อน

      @@Alibeee87 hey there , i have same issu , please tell me what you did to fix that problem?

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

    im doing internship in company and for nodejs and express im watching your video . i like how to teach ..... and plz don`t do copy paste for small function or tell us where this code we can get . for cors you paste some code .. thank you

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

      Thank you for the feedback. You can find info for cors by searching for it on npmjs.com 🚀

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

    Sorry could some one please tell me what this line of code means app.use(express.urlencoded({extended: false}))

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

    Which theme is he used??

  • @DeepakGupta-pz4fx
    @DeepakGupta-pz4fx 2 ปีที่แล้ว

    Please make api node video

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

    also
    ~ u ( K CI/CD

  • @funkebello1738
    @funkebello1738 8 หลายเดือนก่อน +1

    can you make a github cheat for roblox?

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

    Dave i cannot understand why we use routers, i mean what purpose we used it? Give me some docs, please!

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

      Hi IA, we use routers to organize our code. We could code everything in one file, but that would be a mess. We want clean and organized code. The documentation for routers in Express is here: expressjs.com/en/starter/basic-routing.html

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

      @@DaveGrayTeachesCode Thanks, and now i got it. Thanks a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

    the rate at which nodejs is releasing small incremental versions[minuscule, inconsequential]
    I'll have to hire some dedicated idiot just to keep reminding me and perform the repetitive task.

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

    Super tutorial but i ended up with 'Cannot create property 'next' on string '^/$|/index(.html)?', too much beers for me tonight, will retry tomorrow ;). But i won't give up !

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

      You'll get it tomorrow! 💯 Compare to my source code at the course resources link in the description.

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

      You were right, i found my mistake : just wrote router(.....) instead of router.get(....) inside subdir router. It's a shame 🥴

  • @Pareshbpatel
    @Pareshbpatel 10 หลายเดือนก่อน

    {2023-10-06}