I am trying to test my routes using the postman. The below is my user.model.js file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const userSchema = new Schema({
username: {
type: String,
required: true,
unique: true,
trim: true,
minlength: 3
},
}, {
timestamps: true,
});
const User = mongoose.model('User', userSchema);
module.exports = User;
My router file for the user is below
const router = require('express').Router();
let User = require('../models/user.model');
router.route('/').get((req, res) => {
User.find()
.then(users => res.json(users))
.catch(error => res.status(400).json('Error: ' + error));
});
router.route('/add').post((req, res) => {
const username = req.body.username;
const newUser = new User({ username });
newUser.save()
.then(() => res.json('User added!'))
.catch(error => res.status(400).json('Error: ' + error));
});
module.exports = router;
each time when I am trying to test the post route for user I am getting "Error: ValidationError: username: Path username
is required." error
below is the screenshot of my postman
Could anyone please help me in figuring out where I am wrong.