How to add a User Model in REST APIs?
top of page

How to add a User Model in REST APIs?

We are using React app I will link that in our downloads so that you dont have to worry about the frontend. I will make Blogs on Frontend once we finish REST APIs and how we can deploy our app for free(Node app)


Make a new File in our model file where we want to make our user model


So it totally depends on you how you should make your User Model basically I will be using this model for my authentication purpose so i will add email, password and many other things in that. We are using Mongoose soo our model will look like this. there are some routes we want to add in this soo lets add those too in our User Model

const mongoose = require('mongoose'); const Schema = mongoose.Schema; const userSchema = new Schema({ email: { type: String, required: true }, password: { type: String, required: true }, name: { type: String, required: true }, status: { type: String, required: true }, posts: [{ type: Schema.Types.ObjectId, ref: 'Post' }] }) module.exports = mongoose.model('User', userSchema);



Make a new file in our routes

const express = require('express') const router = express.Router(); router.put('/signup');


module.exports = router


In our main app we need to import our authentication


const authRoutes = require('./routes/auth'); these ./ may varry because i am up level so i used 1 dot if you are 2 level back on your database then use 2 dots then it will be ../routes/auth

I will link the whole file in our projects

app.use('/auth', authRoutes);

3 views0 comments

Recent Posts

See All

SQL UNION GROUP BY

SQL UNION Operator UNION operator is used to combine the results of two or more SELECT statements Every SELECT statement within UNION must have the same number of columns The columns must also have si

SQL JOIN

JOIN clause is used to combine rows from two or more tables. INNER JOIN === selects records that have matching values in both tables SELECT Orders.OrderID, Customers.CustomersID, Orders.OrdersDate FRO

bottom of page