How to Validate Requests in Node JS (with Joi validator) | Node JS Tutorial
Ғылым және технология
In this video you'll learn how to validate API requests using the Joi validator library!
Joi: joi.dev/api/?v=17.6.0
Code: github.com/nikitapryymak/basi...
Contact Me: onelightwebdev@gmail.com
Github: github.com/nikitapryymak
Support Me: www.paypal.com/paypalme/nikit...
#nodejs #joivalidator #nodevalidation
Пікірлер: 47
My first time watching ds n d explanation is top notch
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!
@nikita-dev
Жыл бұрын
thanks so much!
Thank you so much for this. Now, I will replace the "express-validator" with "joi".
Just want to say thank you. You deserve way more subscribers! Really helping me with my software development course
@nikita-dev
Жыл бұрын
thank you!
Extremely concise, thanks!
Thanks for this, it was so helpful. I wish I could ask you some questions privately.
Thank you so much for this. You're super concise and eloquent. +1 subscriber
Nice work. That is lots of informative video
Very simple and helpful! 😊
very professional and helpful.
Loved this!! Keep it up
This was really helpful, thanks
Thanks! You helped me a lot!
thank u so much for that amazing tutorial.
Excellent video!
Very helpful bro, keep it up
Thanks! It's very useful)
awesome tut thankyou so much
Great video. Thanks
Thank you! 🎉
thank you so much
Thanks!
Nice job!
@nikita-dev
Жыл бұрын
thank you!
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
Жыл бұрын
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
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
10 ай бұрын
yes, you can add custom error messages using Joi: stackoverflow.com/questions/48720942/node-js-joi-how-to-display-a-custom-error-messages
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"
we can use async direct inside of Joi schema? mean user fetch form db
@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.
How can I validate files?
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
10 ай бұрын
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)
How to implement custom message for each property?
@nikita-dev
2 жыл бұрын
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
which is better express validator or joi
@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
Can you share your font and theme and terminal theme please 🙁💚
@nikita-dev
10 ай бұрын
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
10 ай бұрын
@@nikita-dev 💚
Hi🎉
Do some Udemy courses
@nikita-dev
Жыл бұрын
I plan to make some courses in the upcoming months
Thanks! You helped me a lot!