April 2020
Intermediate to advanced
716 pages
18h 55m
English
We will implement the user model in the server/models/user.model.js file and use Mongoose to define the schema with the necessary user data fields. We're doing this so that we can add built-in validation for the fields and incorporate business logic such as password encryption, authentication, and custom validation.
We will begin by importing the mongoose module and use it to generate a UserSchema, which will contain the schema definition and user-related business logic to make up the user model. This user model will be exported so that it can be used by the rest of the backend code.
mern-skeleton/server/models/user.model.js:
import mongoose from 'mongoose'const UserSchema = new mongoose.Schema({ … })export default ...Read now
Unlock full access