While checking an endpoint using POST method in postman, there is no error.
.env file with PORT, MONGO_URI and the mongoose connection is set up properly, and returning no error.
code in my app.js
const express = require('express')
require('./db/db')
const dotenv = require('dotenv')
const app = express()
const mongoose = require('mongoose')
dotenv.config({ path: 'config.env' })
const PORT = process.env.PORT
const User = require('./model/user')
app.get('/', (req,res)=>{
res.send('Hello')
})
app.post('/create-user', async(req, res)=>{
const user = await User({
fullname: 'John5 Doe',
email:'[email protected]',
password:'12345'
});
await user.save();
res.json(user);
})
app.listen(PORT, () =>{
console.log(`app is running on port ${PORT}`)
})
But the data is not saved in MongoDB database. As I check the endpoint in postman and refresh the collection in mongo db, it is showing this page.
how do I fix this?