I'm having trouble with my server routes. is there any problem with my routes? or a problem with the code?
I have checked all the possible question answers.
I'm having trouble with my server routes.
used thunderclient to send request
when I route it shows this
I tried to set thunder client POST to GET but got the same error
Index.js
const connectToMongo = require('./db');
const express = require('express')
connectToMongo();
const app = express()
const port = 5000
//Available Routes
app.use('/api/auth', require('./routes/auth'))
// app.use('./api/notes', require('./routes/notes'))
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
my auth.js where login and register exist.
const express = require('express');
const User = require('../models/User');
const router = express.Router();
const { body, validationResult } = require('express-validator');
// Create a User using: POST "/api/auth/". Doesn't require auth
router.post('/',[
body('name').isLength ({min: 3}),
body('email').isEmail(),
body('password').isLength ({min: 5})
], (req, res)=>{
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
res.send(req.body);
})
module.exports = router
my user.js which shows user data
const mongoose = require('mongoose');
const {Schema}= mongoose;
const UserSchema = new Schema({
name:{
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true
},
password:{
type: String,
required: true
},
date:{
type: Date,
default: Date.now
},
});
module.exports = mongoose.model('user', UserSchema);