From the course: Node.js: Securing RESTful APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create the user model

Create the user model

From the course: Node.js: Securing RESTful APIs

Start my 1-month free trial

Create the user model

- [Instructor] The next step in building a secured API is to add users that can register and log into the application. And for that to happen, we need a user schema. So let's get back to VS Code, and in the models folder, I'll create a few file. So I'm going to go ahead and click new file here, and then call this user model dot JS. And if you created that file outside of the folder here, all you have to do is drag and drop that file inside of the folder, and then yes, move it, and then the file's going to be in the right folder. So let's go ahead and start by importing mongoose from mongoose. And then, let's go ahead and create a variable that we'll call schema. And that looks very similar to this CR model here. So if you don't want to waste cycles in typing all these extra stuff, what you can do is copy and paste that section here, like so, and then bring it back to the model here. So you have the first line…

Contents