What is Middleware in Express JS? | Node.js Tutorials for Beginners

  Рет қаралды 40,888

Dave Gray

Dave Gray

Күн бұрын

Пікірлер: 74
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
This tutorial will help you learn all about middleware in Express JS. It applies built-in middleware, custom middleware that we will construct to log events and handle errors, and third party middleware. If you're just getting started with Node.js, you may want to start at the beginning of the Node.js for Beginners tutorials playlist found here: kzbin.info/aero/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw
@Alibeee87
@Alibeee87 2 жыл бұрын
Thank you for all your help! I appreciate you mentioning keyboard commands as well, that's fantastic info for a beginner!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! 🙏
@viciousinsights6902
@viciousinsights6902 2 жыл бұрын
This has been truly enlightening, this series has helped me tremendously with the aspects of node & expressjs I had been struggling with. I look forward to learning more from you in the future!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it helped! 🚀
@ahmad-murery
@ahmad-murery 3 жыл бұрын
Well explained Dave, Middleware can be very handy to allow only authentic users to access certain pages, I recently started using the Rest Client extension for VS Code instead of Postman, I found it easier to work with as I don't have to leave VS Code to test my API, it also let me have all my requests in a plain text file that can be included side by side with the app files. Thanks Dave 🚀
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Thank you Ahmad. 🙏 Yes, there are many good applications of middleware including authentication. Is the VS Code extension you are using called Thunder Client? I have heard good things!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
@@ahmad-murery thank you my friend! I will check them both out and compare. Have a great weekend!
@ahmad-murery
@ahmad-murery 3 жыл бұрын
@@DaveGrayTeachesCode Have a great day you too my friend, if possible, make a video about the comparison and maybe put it under the web dev tools playlist, regards
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
@@ahmad-murery thank you - great idea, Ahmad!
@juangomez874
@juangomez874 2 жыл бұрын
Dave, you are my new hero. Thanks a lot for these videos, they had helped me a lot. Very very clear. Keep up the good job.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you for the kind words, Juan! 🙏
@pets_talk
@pets_talk 2 жыл бұрын
great tutorial! Coming from the frontend world, it really helps me to undestand how the backend works!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Happy to help! Thanks Natalia! 🙏💯
@NaviaryMusic
@NaviaryMusic Жыл бұрын
Thanks Dave!! My websites coming along nicely!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Fantastic!
@saquibansari7866
@saquibansari7866 Жыл бұрын
6:02 Check this time stamp And can you please elaborate that the path of css file you have assigned is different as we used to assign without middlware. I found it after searching alot that the path of middlware and the path of opening html file in a browser will be different. I still don't know why it is so. So kindly clear this out.. please please please please❤❤❤❤❤
@wgllgw
@wgllgw 3 ай бұрын
Hi Dave, you must be a very good teacher/mentor. I would love to work under/learn from someone like you! You addressed a lot of pertinent questions, in a prudent sequence. Plus your explanations are clear and concise. It lends a lot of motivation to why things are they way they are (these are the hardest thing to Google!). Thank you so much for taking the time and effort to share your knowledge and wisdom!
@ampinkus
@ampinkus 9 ай бұрын
Hi Dave, I just finished this module of the course and o far it is really excellent! I would only recommend that each module should start with an introductory slide explaining what will be developed in the module and perhaps a graph with the interaction of the different functions that will be implemented.
@ofofononoumoren
@ofofononoumoren Жыл бұрын
Absolutely great video. Just for improvement purpose, it's best to import logger as a single value (const logger = require('./destination')) rather than as an object with named properties since that not how it was exported in the logEvents file. Even if, it doesn't matter anyways. Thanks for this very elaborate module, Dave.
@MrQVeeBoo
@MrQVeeBoo Жыл бұрын
Very nice explanation. Step by step. Easy to follow. Thx
@loikvokhidov7688
@loikvokhidov7688 Жыл бұрын
algorithm should recommend these videos to all the people who want to learn NodeJS.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you!
@cyberpaimpol
@cyberpaimpol 2 жыл бұрын
Super tutorial, progression is smooth and so interesting, thx !
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Happy to hear that!
@piotrekjazz1287
@piotrekjazz1287 2 жыл бұрын
Apart from the great content, thanks a lot also for the source code, that slowly becomes a youtube standard, at least at most of the popular channels.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome. 🙏 Early on in this series, I don't think I provided it. I often think typing out the code helps students learn. As we started to put together a REST API project I thought the source code would be good to build upon as the series progressed.
@piotrekjazz1287
@piotrekjazz1287 2 жыл бұрын
@@DaveGrayTeachesCode Good point, but most of the time you want to check/test just a small bits and then it is problematic writing everything.
@moiraleon8744
@moiraleon8744 2 жыл бұрын
Quick question, what extension do you have that allows your file names in your Explorer tab to have different icons and colors?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
That is vscode-icons. I recommend 5 extensions here: kzbin.info/www/bejne/roLGoYScetqgh9k
@Uniqlo921
@Uniqlo921 5 ай бұрын
Hey dave, at @34:51, I accidentally forgot the "else" in the if else block for req.accepts('json'). So it was if(req.accepts('html') followed by if(req.accepts('json'). When I tested with my browser, I got the JSON response. So it seems that my request accepted both html and json. However, I noticed that you said we needed postman to test the json functionality, which I agreed with until I hit my issue. Do you know why the above happened. I also wanted to thank you for making such a fantastic and comprehensive tutorial on Node. I am currently using this to get out of my automated testing pigeonhole :)
@unique3345
@unique3345 2 жыл бұрын
A very useful tutorial!!!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it was helpful!
@DeepakGupta-hj2dv
@DeepakGupta-hj2dv 3 жыл бұрын
Can you please make a video node JS microservices crash course
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 жыл бұрын
Thank you for the good suggestion! 🙏
@mertfromhell
@mertfromhell Ай бұрын
im edging to this playlist rn
@DrCash7
@DrCash7 Жыл бұрын
Ona managed vps and keep running into cors error when my front end loads and talks to the backend. I've added the cors settings after the installed apps and still running into cors errors. Need halp
@soudaminipanda
@soudaminipanda Жыл бұрын
Very nice tutorial. Very easy to understand
@baxtables
@baxtables Жыл бұрын
when a new Error("Not allowed by CORS") is created, does the app.use(errorHandler) receive it automatically, because it has a first arguement as err?
@brandonjoaocastillo7490
@brandonjoaocastillo7490 Жыл бұрын
Why you dont use next() in the errorHandler function? you did it in logger, its because is the last middleware or something like that?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You are correct - if my memory is right, it is last.
@denmccormik7654
@denmccormik7654 Жыл бұрын
Thank you for the lesson. Do you know why browser doesn't allow to fetch from console from it's starting window (when url is empty, when we just opened the browser without starter page)? I thought that origin just will be undefined but everything would work.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
The browser always implements cors. Ref: developer.mozilla.org/en-US/docs/Web/HTTP/CORS
@tabliqatchi6696
@tabliqatchi6696 2 жыл бұрын
This is gem people!
@keithbacalso9433
@keithbacalso9433 2 жыл бұрын
Even I did not removed the `.css` I can still access it in the browser.... ? why?
@bnmbnm7278
@bnmbnm7278 2 жыл бұрын
24:56 Excuse me, can you explain why the code(line 80-83) work? How does it work? I cannot understand...Thank you...
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
app.use() indicates we are going to use middleware. We're passing in an anonymous function as the middleware. The function is sending an http status code of 500 along with the error message in the response to the client.
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Amazing tutorial thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Sona! 💯
@NoorNoor-bl2jr
@NoorNoor-bl2jr 3 ай бұрын
There is no logs file in your git repository.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 3 ай бұрын
Yes, you should create your own logs.
@kkomax7
@kkomax7 Жыл бұрын
This tut hasn't been liked enough. I usually don't comment to thank, but thanks Dave
@ramziosta
@ramziosta 2 жыл бұрын
I got an error optionsSuccessStatus undefined , so I declared let optionsSuccessStatus; outside corsOptions, and that removed the error and got everything to work fine. is that an allowed hack?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
I would not do that. I suggest downloading my source code and comparing to yours to find the difference and what caused your error.
@MohammadBarghamadii
@MohammadBarghamadii 2 жыл бұрын
Thank you so much
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Mohammad!
@Pareshbpatel
@Pareshbpatel 11 ай бұрын
A comprehensive tutorial on Middleware in Express, beautifully presented. Thanks, Dave {2023-10-05}: implemented
@AuxiliaryOfficial
@AuxiliaryOfficial 2 жыл бұрын
im looking for your typescript tutorial
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
It is coming soon! 🚀
@AuxiliaryOfficial
@AuxiliaryOfficial 2 жыл бұрын
@@DaveGrayTeachesCode really thanks, typescript + react 😍
@sdfsdfsdffdsfsdfsd123
@sdfsdfsdffdsfsdfsd123 2 жыл бұрын
thank you.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Welcome!
@vigneshb5717
@vigneshb5717 Жыл бұрын
so far ok completed the second video
@alirezahekmati7632
@alirezahekmati7632 2 жыл бұрын
🚀
@shineLouisShine
@shineLouisShine 2 жыл бұрын
Thank you very much for this lesson. With all due respect. and I do sincerely and deeply have A LOT of respect for everything you are doing here: For me, the last part where you immediately say to "Like" the video is a bit too aggressive, Without a single second of silence to breathe, to process, and to execute the "Like" on our own - Without you asking us to do so, but just because of a natural sense of gratitude. I feel less sympathy for this kind of... "strategy"(?), because... Whoever likes the video - will give them a "Like", And whoever likes to subscribe - will certainly subscribe. Furthermore, think of people who already subscribed to your channel, And yet don't have any other choice but to listen to this request in the end of each and every video, Regardless of the fact that they already did it. My suggestion (/request) : Give your viewers a little bit more credit 😌 (in addition, there is actually a graphic invitation to subscribe during the videos already...)
@Jazz__Dev
@Jazz__Dev Жыл бұрын
is channel is not the only one you know... As a matter of fact, I love listening to that part... just watch the tutorial and move on... All these are absolutely unnecessary..
@Jazz__Dev
@Jazz__Dev Жыл бұрын
fetch('localhost:3500') Promise {} VM1113:1 GET localhost:3500/ net::ERR_FAILED (anonymous) @ VM1113:1 VM1113:1 Uncaught (in promise) TypeError: Failed to fetch at :1:1 HI Dave, not sure if i'm the only one getting this particular error and i'm not even sure where to fix it... Why is the console fetch throwing that error please?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
The fetch is failing, but it is difficult to say why from here. After it fails, you get a type error. Go back over it and check your source code compared to mine. One little thing can make a difference.
@AdityaDey424
@AdityaDey424 Жыл бұрын
Hey have you solve the issue? I also get this problem. If you solve this then please told me the solution.
@kaustavbhattacherjee7952
@kaustavbhattacherjee7952 Жыл бұрын
I'm getting the same error as well even when I use the exact same snippet
@shreyalanka
@shreyalanka 9 ай бұрын
Same here😢
@Riowx7
@Riowx7 6 ай бұрын
Same but i am also not getting data in log file when i used fetch('localhost:3500') in google.com
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 47 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 116 МЛН
💩Поу и Поулина ☠️МОЧАТ 😖Хмурых Тварей?!
00:34
Ной Анимация
Рет қаралды 1,5 МЛН
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 8 МЛН
What is Express middleware and how does it work? (in-depth)
30:28
Zach Gollwitzer
Рет қаралды 61 М.
What is Middleware?
10:11
IBM Technology
Рет қаралды 99 М.
NextJS Parallel Routes Explained with a Simple Example
14:04
Dave Gray
Рет қаралды 11 М.
Introduction to Node JS | Node.js Tutorials for Beginners
17:09
Learn Express Middleware In 14 Minutes
14:48
Web Dev Simplified
Рет қаралды 398 М.
Node.js Crash Course
2:06:35
Traversy Media
Рет қаралды 178 М.
Error Handling in NodeJS (Complete Guide) | Node Tutorial
17:54
Nikita Dev
Рет қаралды 42 М.
Игровой руль - штука годная 👍
0:50
RxFx
Рет қаралды 3,4 МЛН
iPhone 16 для НИЩЕБРОДОВ!
0:51
ÉЖИ АКСЁНОВ
Рет қаралды 8 МЛН
Apple Event - September 9
1:38:50
Apple
Рет қаралды 26 МЛН