How to Validate Requests in Node JS (with Joi validator) | Node JS Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • In this video you'll learn how to validate API requests using the Joi validator library!
    UPDATED 2024 - I would strongly recommend using Zod instead of Joi, because of it's built-in type-safety (zod.dev)
    Joi: joi.dev/api/?v...
    Code: github.com/nik...
    Github: github.com/nik...
    Support Me: www.buymeacoff...
    Contact Me: nikitadev292@gmail.com
    #nodejs #joivalidator #nodevalidation

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

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

    Thank you so much for this. Now, I will replace the "express-validator" with "joi".

  • @exrocker47
    @exrocker47 ปีที่แล้ว +4

    Hey man! I just wanted to say THANK YOU! Your content quality is seriously awesome. I have noticed you dont share too many vids. Dont let the algorithm get you and keep up the good work!

  • @onigbindedavid6630
    @onigbindedavid6630 2 หลายเดือนก่อน

    My first time watching ds n d explanation is top notch

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

    You deserve a million subscribers. Thank you

  • @Sir_Pickle
    @Sir_Pickle ปีที่แล้ว +5

    Just want to say thank you. You deserve way more subscribers! Really helping me with my software development course

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

    Nice work. That is lots of informative video

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

    Thanks for this, it was so helpful. I wish I could ask you some questions privately.

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

    Extremely concise, thanks!

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

    Thank you so much for this. You're super concise and eloquent. +1 subscriber

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

    Great video. I just wonder why could not we just export a validator(payload) function that would validate the payload against predefined schema. What's the point of returning a function instead of validation result itself ?

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว +1

      you could definitely export a function that takes in a schema and payload, for example:
      const validate = (schema, payload) => schema.validate(payload);
      but then you would have to pass in the same schema every time you want to use it, as opposed to defining it once, and then using the function that is returned. Hope that makes sense

  • @sultanmatthews-cy8uz
    @sultanmatthews-cy8uz ปีที่แล้ว

    Loved this!!
    Keep it up

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

    thank u so much for that amazing tutorial.

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

    Very simple and helpful! 😊

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

    very professional and helpful.

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

    Very helpful bro, keep it up

  • @KelechiNwaji-fg3vn
    @KelechiNwaji-fg3vn ปีที่แล้ว

    This was really helpful, thanks

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

    Thanks! You helped me a lot!

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

    awesome tut thankyou so much

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

    Excellent video!

  • @AbaijanAlimbekov
    @AbaijanAlimbekov 2 หลายเดือนก่อน

    Nikita Hi , Is this methot working with chenging data on server too . If not how can I make that? Pls can you make new video about that : " how to patch data on next js with Joi libruary"

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

    thanks, could you do the same video but creating a middleware validator these time programmed in OOP.
    Also can we create custom message responses with joi ?

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว +1

      yes, you can add custom error messages using Joi: stackoverflow.com/questions/48720942/node-js-joi-how-to-display-a-custom-error-messages

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

    Thanks! It's very useful)

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

    Great video. Thanks

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

    What should I use if I want an unique value? if I signup with an email and I don't want you to have to create an account with the same email what should I use?

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว

      First you would validate that the email from the request is actually a valid email. Then in your controller make sure to add some business logic that verifies that the email is not in use (ie: fetching a user for that email, verifying that no user exists with that email)

  • @lannguyen-xr1xl
    @lannguyen-xr1xl ปีที่แล้ว

    thank you so much

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

    Thanks!

  • @edu.paixao
    @edu.paixao ปีที่แล้ว

    Thank you! 🎉

  • @ABUTAHER-wg7gz
    @ABUTAHER-wg7gz ปีที่แล้ว

    we can use async direct inside of Joi schema? mean user fetch form db

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว

      A Joi schema is not the right place to make a database call. You should first validate the incoming request (make sure they passed a valid userId, email, etc.), and once the Joi schema validates it, then you should make the database call. You only want to make database calls after you've verified that it was a proper request.

  • @ehSamurai3483
    @ehSamurai3483 4 หลายเดือนก่อน

    How can I validate files?

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

    Nice job!

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

    which is better express validator or joi

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว

      Joi is a bit more popular and can be used for general object schema validation, while express-validator is used specifically as express middleware and is tightly coupled to express JS. I would recommend using Joi in most cases

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

    How to implement custom message for each property?

    • @nikita-dev
      @nikita-dev  2 ปีที่แล้ว +1

      you can call the messages() method at the end of the Joi field, and pass in an object with the different error types as the keys, and the custom error message as the value.
      Here is an example: runkit.com/embed/fnfaq3j0z9l2
      Here is the list of error types: github.com/sideway/joi/blob/master/API.md#list-of-errors

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

    Can you share your font and theme and terminal theme please 🙁💚

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว +1

      VSC theme: "Atom One Dark" with the "Material Font Icons" extension.
      Font: "MonoLisa, Menlo, Monaco, 'Courier New', monospace"
      The terminal theme is a custom one I made using iTerm2

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

      @@nikita-dev 💚

  • @alefali542
    @alefali542 9 หลายเดือนก่อน

    Hi🎉

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

    Do some Udemy courses

    • @nikita-dev
      @nikita-dev  ปีที่แล้ว

      I plan to make some courses in the upcoming months

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

    Thanks! You helped me a lot!