Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 74

  • @jgoebel
    @jgoebel  3 года назад +3

    Please let me know if you have more video ideas

    • @yashagrawal8639
      @yashagrawal8639 3 года назад

      Please show how to validate image using custom express-validator

    • @arshad-m-vlog
      @arshad-m-vlog 3 года назад +1

      Custom Error Handler please.

    • @sajaygopalakrishnan9184
      @sajaygopalakrishnan9184 2 года назад

      Great tutorial, could you please add something on writing unit test case, like mocking validationResult with typescript and jest

    • @spirobel
      @spirobel 2 года назад

      can you try the express-openapi-validator package?

  • @spirobel
    @spirobel 2 года назад +1

    I like the introduction in the beginning on how to setup the project. Very to the point

  • @Finn-jp6pn
    @Finn-jp6pn 2 года назад +3

    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.

    • @jgoebel
      @jgoebel  2 года назад +1

      Happy to help!

  • @johanhellberg9677
    @johanhellberg9677 Год назад

    Thanks for a great tutorial on express validator. Appreciate that you explained file and folder structure for someone just starting with backend development.

    • @jgoebel
      @jgoebel  Год назад

      Glad it was helpful!

  • @_slier
    @_slier 2 года назад

    I love your obsession with best design architecture

    • @jgoebel
      @jgoebel  2 года назад +2

      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 😀

  • @joeygarcia7826
    @joeygarcia7826 2 года назад

    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!!

  • @seokyungkim1012
    @seokyungkim1012 2 года назад +1

    Easy to understand even I live in non-english country. Thank you! :)

    • @jgoebel
      @jgoebel  2 года назад

      Glad to hear that!

  • @andyslezak3606
    @andyslezak3606 3 года назад +1

    Fantastic and thorough. Thank you!

    • @jgoebel
      @jgoebel  3 года назад

      thx Andy, I'm glad you found it useful 👍

  • @girishm3421
    @girishm3421 Год назад

    Thank you, Please do more videos

  • @ofeenee
    @ofeenee 2 года назад

    More videos like this please!

  • @francomarelli1919
    @francomarelli1919 Год назад

    usefull video and well explained! thanks man!

    • @jgoebel
      @jgoebel  Год назад

      Glad you enjoyed it!

  • @ofeenee
    @ofeenee 3 года назад +1

    Thank you! Well presented and well explained!

    • @jgoebel
      @jgoebel  3 года назад

      thx Ofeenee, I hope it helped 👍

  • @CyberadictosOficial
    @CyberadictosOficial 3 года назад

    thanks friend! grettings from Peru!

    • @jgoebel
      @jgoebel  3 года назад

      greetings back 😁

  • @imanqoly
    @imanqoly 3 года назад

    I like your video because it causes "what the hell I was doing" moment for me

  • @fc978
    @fc978 Год назад

    You are amazing!

  • @pavelgutsal4969
    @pavelgutsal4969 Год назад

    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.

  • @arnaudroncari2468
    @arnaudroncari2468 2 года назад

    Thanks for the help !

    • @jgoebel
      @jgoebel  2 года назад

      thx Arnaud, always happy to help 👍

  • @aymenboudissa3927
    @aymenboudissa3927 Год назад

    Good Practice 🤩🤩

  • @VitalikAwesome
    @VitalikAwesome 3 года назад +1

    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)

    • @jgoebel
      @jgoebel  3 года назад

      thx Віталік, I will add it to my list of potential topics 👍

  • @vikrantprasad7137
    @vikrantprasad7137 3 года назад

    Thanks for making this video AMAZINGGGGGGGGGGGG

    • @jgoebel
      @jgoebel  3 года назад

      you're welcome Shanaya

  • @alexandrefaculdade
    @alexandrefaculdade 3 года назад

    Thanks! Perfect video.

    • @jgoebel
      @jgoebel  3 года назад

      thx Alexandre 👍

  • @Shraddha-sarvaiya
    @Shraddha-sarvaiya 2 года назад

    Thanks. This video is very helpful for me. But when i upload image then it's value is not showing. Can you suggest me?

  • @xenizs9112
    @xenizs9112 3 года назад

    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.

    • @jgoebel
      @jgoebel  3 года назад

      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

    • @xenizs9112
      @xenizs9112 3 года назад

      ​@@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

    • @jgoebel
      @jgoebel  3 года назад +1

      @@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

  • @Cmxmxmmx7
    @Cmxmxmmx7 2 года назад +1

    Hi! What is the difference between check and body? Which should we use? Thanks for great videos.

    • @jgoebel
      @jgoebel  2 года назад

      according to docs: "Same as check([fields, message]), but only checking req.body."
      express-validator.github.io/docs/check-api.html#bodyfields-message

  • @vaibhavrijumishra8249
    @vaibhavrijumishra8249 Год назад

    How do I check for number only in express-validator?

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 года назад

    Awesome video ++++++++++

  • @saidleonardooyola2203
    @saidleonardooyola2203 3 года назад

    Me fue de gran utilidad, muchas gracias 🙂

    • @jgoebel
      @jgoebel  3 года назад +1

      you're welcome Said 👍

  • @julianyepes5784
    @julianyepes5784 3 года назад

    excelent tutorial

    • @jgoebel
      @jgoebel  3 года назад

      thx Julian 👍

  • @scuzzoo
    @scuzzoo Год назад

    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

  • @arshad-m-vlog
    @arshad-m-vlog 3 года назад

    Thanks for this video, can you please make a video on custom error set-up.

    • @jgoebel
      @jgoebel  3 года назад +1

      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

    • @arshad-m-vlog
      @arshad-m-vlog 3 года назад

      @@jgoebel thanks a lot for this.

  • @ahmadreza2189
    @ahmadreza2189 2 года назад

    thanks a lot

    • @jgoebel
      @jgoebel  2 года назад

      You are most welcome

  • @IranzinhoBRG
    @IranzinhoBRG 2 года назад

    Do you prefer express-validator over Yup for request data validation?

    • @jgoebel
      @jgoebel  2 года назад +1

      Hi Iran, I don't have a real preference there. If I use express, I use express-validator

  • @mannumannu9200
    @mannumannu9200 3 года назад

    Please tell whats your recommendation? JOI, yup or express-validator?

    • @jgoebel
      @jgoebel  3 года назад +1

      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.

  • @alimertcakar1894
    @alimertcakar1894 3 года назад

    What if you validate nothing? just asking out of curosity. Worst thing they can do fill db with invalid data

    • @jgoebel
      @jgoebel  3 года назад

      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.

    • @alimertcakar1894
      @alimertcakar1894 3 года назад

      @@jgoebel Thank you, for the tutorial and the answer.

  • @thenstyle1
    @thenstyle1 3 года назад +1

    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 🔥

    • @jgoebel
      @jgoebel  3 года назад +1

      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

  • @johnnykan7484
    @johnnykan7484 2 года назад

    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)

    • @jgoebel
      @jgoebel  2 года назад

      both are good in my opinion