From the course: Node.js: Security
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Data handling with type and validation
From the course: Node.js: Security
Data handling with type and validation
- [Instructor] When handling data on your server the best first line of defense is to do validation and type assertion. This way, the data sent is already sanitized to be of a certain type and you avoid sending dangerous scripts to the server. Let me demonstrate. So go into the project and open the folder called models and then click on crmModel. And this is where we actually define the type of our schema. So right now if you take a look at firstName, lastName, email, company, phone, and created_date we expect a type. So we expect a type of String, String, and email for String and then Number for phone and then we expect a type Date for the created_date. So if we pass a number to firstName, right there and then it's gonna break. So we're not gonna be able to pass a number to String or a string to the Number here. So this is one of the first thing you need to do. So when you define your schema, make sure you define a type for each of your properties inside of your object that you are…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.