Это видео недоступно.
Сожалеем об этом.
express-validator Node.js tutorial
HTML-код
- Опубликовано: 12 авг 2024
- 🔥More exclusive content: productioncoder.com/you-decid...
Twitter: / _jgoebel
Blog: productioncoder.com
Website: jangoebel.com
Code: github.com/productioncoder/no...
In this video, we take a look at the express-validator npm package. This package allows you to validate incoming request payloads and it allows you to check whether the payload conform to the format that you are expecting.
We cover how to create request body validation middlewares and how properly organize your project with express-validator.
00:00 express-validator project setup with Typescript
03:10 creating a express server with validation middleware
04:52 understanding express-validator chains
06:52 trying out request-validator
09:25 exists validator chain with falsy checks
12:07 moving request body validation to its own middleware
15:36 moving express validator schema checks to a separate file
18:50 moving the routes to another
21:17 customizing error messages in express-validator
22:45 conclusion
Please let me know if you have more video ideas
Please show how to validate image using custom express-validator
Custom Error Handler please.
Great tutorial, could you please add something on writing unit test case, like mocking validationResult with typescript and jest
can you try the express-openapi-validator package?
I like the introduction in the beginning on how to setup the project. Very to the point
thx
Thank you! I love to watch your videos because you always show the proper way to do things. As a junior dev with not many mentors, your videos are very helpful.
Happy to help!
Thanks for a great tutorial on express validator. Appreciate that you explained file and folder structure for someone just starting with backend development.
Glad it was helpful!
I love your obsession with best design architecture
this is born out of pure laziness actually because I want to do it so that I do not have to refactor it later on 😀
GREAT Video! I am working on a project like this at work, I am going to play with this at home now that you showed me a simple way to run an express server locally and now I can test all the ways I can validate the payload. Thank you!!
Easy to understand even I live in non-english country. Thank you! :)
Glad to hear that!
Fantastic and thorough. Thank you!
thx Andy, I'm glad you found it useful 👍
Thank you, Please do more videos
thx Girish
More videos like this please!
usefull video and well explained! thanks man!
Glad you enjoyed it!
Thank you! Well presented and well explained!
thx Ofeenee, I hope it helped 👍
thanks friend! grettings from Peru!
greetings back 😁
I like your video because it causes "what the hell I was doing" moment for me
thx 👍
You are amazing!
You too!!
I actually made that error on 15:25 , even though it was emhesized. Took me about an hour to notice it). Thought my express-validator package version was out of date. PS - it was.
Thanks for the help !
thx Arnaud, always happy to help 👍
Good Practice 🤩🤩
thx Aymen
Thanks for video! You man are cool ! Could you make lessons about NestJs it would be cool because you are explaining everythig clear and there is still no normal video about it(sorry for english)
thx Віталік, I will add it to my list of potential topics 👍
Thanks for making this video AMAZINGGGGGGGGGGGG
you're welcome Shanaya
Thanks! Perfect video.
thx Alexandre 👍
Thanks. This video is very helpful for me. But when i upload image then it's value is not showing. Can you suggest me?
better than yup imo, it manages to cover more use cases when handling async code, also it supports stopping running validations if a specific one fails with the method bail() which yup lacks, and so.
Hi Xenizs true, I think you can set an option to stop validations earlier. Although I personally would always try to run all validations because then the frontend can mark all form fields that contain invalid values in red). Like so the user gets feedback for all his input and can fix everything right away. But that is a matter of preference I suppose
@@jgoebel hi, I think you got me wrong when I said "it supports stop running validations..", I posted an issue about that on yup repo if you want to understand me better (#1318), also, it makes sense what you said about running all validations, tho I'm doing validations on the backend not the frontend
@@xenizs9112 ah yeah sry, I think I wrote the comment in an ambiguous way. So I saw that you can stop the validations with express-validator. I think for yup, you're totally right, that does not seem to be possible. But still on the backend I personally would always run all validations to all errors can be returned to the frontend where they can be displayed at the same time
Hi! What is the difference between check and body? Which should we use? Thanks for great videos.
according to docs: "Same as check([fields, message]), but only checking req.body."
express-validator.github.io/docs/check-api.html#bodyfields-message
How do I check for number only in express-validator?
Awesome video ++++++++++
Big thanks
Me fue de gran utilidad, muchas gracias 🙂
you're welcome Said 👍
excelent tutorial
thx Julian 👍
Would it be possible to check a body for multiple things on one line such as "body('email').isEmail().withMessage("must be valid email").notEmpty().withMessage("email cannot be empty")" or would each check have to be separated if we wanted custom messages. Thanks
Yes, that is possible
Thanks for this video, can you please make a video on custom error set-up.
Hi Mohammad, not sure if I understand the topic you want. Do you mean error handling middleware? I did a video about that: ruclips.net/video/DyqVqaf1KnA/видео.html
but I am considering to make a new one to make it better
@@jgoebel thanks a lot for this.
thanks a lot
You are most welcome
Do you prefer express-validator over Yup for request data validation?
Hi Iran, I don't have a real preference there. If I use express, I use express-validator
Please tell whats your recommendation? JOI, yup or express-validator?
Hi Aiman, I personally don't use joi anymore because hapi.js announced that it will be deprecated and I don't know how good the support is. So I'd go with express-validator, yup or maybe Ajv.
What if you validate nothing? just asking out of curosity. Worst thing they can do fill db with invalid data
Hi Ali, your server could crash because it might expect certain data points (e.g. you try to create a user with an invalid / null email address).
Oftentimes (although we did not cover that in the video), the content is also sanitized (e.g. convert email to lowercase letters, remove all leading and trailing spaces etc.). So I would always recommend to check the incoming data.
@@jgoebel Thank you, for the tutorial and the answer.
Hello Jan! Do you know a good web hoster where you can host your MERN-App in Germany?
I know Heroku and Digital Ocean but I want to host my webapp in Germany, so any recommandation would be appreciated. :)
Thanks for your content, keep on 🔥
Hi Arthur, I am not really aware of one. I'm a big fan of Digital Ocean in general. If the app must be hosted in Germany, then maybe try to go for AWS and pick the Frankfurt data center. As an alternative, you might also consider ovh.de (although that's a French company). Since GDPR also applies in France maybe the requirement of hosting it in Germany can be relaxed to hosting it in the EU
What is your opinion on using express-validator as opposed to yup (as you showed in this video ruclips.net/video/GfHsb6zPugo/видео.html)? It feels like yup is more useful, since you'll be able to reuse the same validation in the frontend (form validation)
both are good in my opinion