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

  Рет қаралды 39,131

Dave Gray

Dave Gray

Күн бұрын

Пікірлер: 80
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
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: kzbin.info/aero/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw
@soniablanche5672
@soniablanche5672 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 3 жыл бұрын
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 3 жыл бұрын
@@DaveGrayTeachesCode Which might be useful in some cases where a specific route requires some additional or different static files
@quasi_verum
@quasi_verum Жыл бұрын
Thank you dave, for providing us with such great tutorial. may God bless you.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome!
@ahmad-murery
@ahmad-murery 3 жыл бұрын
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 3 жыл бұрын
Thank you Ahmad! Yes, I need to compare Thunder Client vs REST Client vs Postman. I appreciate your feedback.
@mohammedalidelbani565
@mohammedalidelbani565 2 жыл бұрын
Cool
@divyanshsharma673
@divyanshsharma673 Жыл бұрын
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.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Great to hear! 💯
@edwilsondasilva9946
@edwilsondasilva9946 2 жыл бұрын
Too bad I can't give more than one like. Your teaching is excellent!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you for the kind words! 💯
@eddiebello9547
@eddiebello9547 8 ай бұрын
a few years late but this was very very helpful, understood everything in this video
@HologramJay
@HologramJay 2 жыл бұрын
Holy cow, Thunder Client is so convienient!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
I agree! 💯
@lazasergiu4558
@lazasergiu4558 2 жыл бұрын
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 жыл бұрын
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
@funkebello1738
@funkebello1738 10 ай бұрын
can you make a github cheat for roblox?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 10 ай бұрын
Fun suggestion!
@ProtikPC_pro_indigo
@ProtikPC_pro_indigo 3 жыл бұрын
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.
@sumantakumalik4887
@sumantakumalik4887 2 жыл бұрын
It is so explained on each concept. I am waiting your advance mern stack project
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you, Sumanta! 🙏
@sagarsunil8818
@sagarsunil8818 7 ай бұрын
am getting an issue , except the get method all other methods are not responding ..its not showing any content to the body
@sagarsunil8818
@sagarsunil8818 7 ай бұрын
help please anyone
@gandalfgrey91
@gandalfgrey91 5 ай бұрын
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
@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
@abdulrahmanagboolaosho3582
@abdulrahmanagboolaosho3582 Жыл бұрын
Sorry could some one please tell me what this line of code means app.use(express.urlencoded({extended: false}))
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Docs: expressjs.com/en/5x/api.html#express.urlencoded
@abdulrahmanagboolaosho3582
@abdulrahmanagboolaosho3582 Жыл бұрын
Thank you
@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 🚀
@MohammadBarghamadii
@MohammadBarghamadii 2 жыл бұрын
Thank you so much, Dave, great tutorial
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it was helpful!
@mohammedalidelbani565
@mohammedalidelbani565 2 жыл бұрын
How to use it
@amoneleais
@amoneleais Жыл бұрын
@assem_ahmed
@assem_ahmed Жыл бұрын
amazing tutorial
@motivational_shorts9429
@motivational_shorts9429 Жыл бұрын
Can you provide any solution export import of express router as in es6? It'll be helpful
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
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 😎
@agus-wesly
@agus-wesly 2 жыл бұрын
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 2 жыл бұрын
recently back from stack overflow and i figured out that i forgot to use the express.json() middleware
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad you found the solution!
@harshitsz8144
@harshitsz8144 11 ай бұрын
@@agus-wesly thanks, i was also facing this problem
@OnlyGoodVibe_
@OnlyGoodVibe_ Жыл бұрын
Which theme is he used??
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
My theme choices: kzbin.infodp4u1NNFhtE
@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 3 ай бұрын
@@Alibeee87 hey there , i have same issu , please tell me what you did to fix that problem?
@akbarganey168
@akbarganey168 2 жыл бұрын
Hi, I'd like to know which other extensions you use when coding nodejs applications
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
I understand. I don't use many though.
@imadbenmadi
@imadbenmadi Жыл бұрын
bro yr amaizing
@ProtikPC_pro_indigo
@ProtikPC_pro_indigo 3 жыл бұрын
also ~ u ( K CI/CD
@MujibnagarKhabor
@MujibnagarKhabor 2 жыл бұрын
very nice
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you, Mujibnagar!
@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 2 жыл бұрын
You were right, i found my mistake : just wrote router(.....) instead of router.get(....) inside subdir router. It's a shame 🥴
@nicolasborges7293
@nicolasborges7293 2 жыл бұрын
Great tutorial!! This is awesome. I'm grateful, it helped me so much
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it helped!
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Amazing tutorial thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! 🚀
@DeepakGupta-pz4fx
@DeepakGupta-pz4fx 3 жыл бұрын
Please make api node video
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
That's next! 💯🚀
@antishandex8984
@antishandex8984 Жыл бұрын
Thanks a lot Dave !
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome!
@jorgeloaiza3406
@jorgeloaiza3406 Жыл бұрын
NIce video.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thanks!
@ubitubee
@ubitubee Жыл бұрын
This is great!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad it helped!
@ashishafk
@ashishafk 2 жыл бұрын
Okay lets get it straight and clear these tutorials are gold.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you, Ashish 🙏
@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 жыл бұрын
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@Pareshbpatel
@Pareshbpatel Жыл бұрын
{2023-10-06}
Миллионер | 1 - серия
34:31
Million Show
Рет қаралды 2,2 МЛН
Стойкость Фёдора поразила всех!
00:58
МИНУС БАЛЛ
Рет қаралды 4,9 МЛН
Node and Express - Routes & Express Router
20:10
WittCode
Рет қаралды 3,5 М.
JWT Authentication | Node JS and Express tutorials for Beginners
1:00:03
Learn Express JS In 35 Minutes
36:03
Web Dev Simplified
Рет қаралды 817 М.
NPM Node Package Manager Modules | NPM Tutorial for Beginners
23:23
Learn Express JS With TypeScript
40:16
TomDoesTech
Рет қаралды 75 М.
NGINX Tutorial - What is Nginx
14:32
TechWorld with Nana
Рет қаралды 186 М.
Миллионер | 1 - серия
34:31
Million Show
Рет қаралды 2,2 МЛН