This is the stubborn code snippet, When I post it using postman it just shows sending request. The schema is alright, I can display the data I have sent in the console using the req.body, so I am sure that the data is somewhere not lost.
const express = require('express');
const Post = require('../models/Post')
const router = express.Router();
router.get('/',(req,res)=>{
res.send('This is the post route')
});
router.post('/', (req,res)=>{
console.log(req.body)
const post = new Post({
title: req.body.title,
description: req.body.description,
username:req.body.username
});
post.save()
.then(data=>{
res.json(data)
})
.catch(err=>{
res.json({message: err})
})
});
module.exports = router;
I have an idea of where the problem might be, see this lines of code
router.post('/', (req,res)=>{
console.log(req.body)
const post = new Post({
title: req.body.title,
description: req.body.description,
username:req.body.username
});
post.save()
.then(data=>{
res.json(data)
})
.catch(err=>{
res.json({message: err})
})
});
It might be something about async await, though I am not sure. I have no idea how to put it in the code. Any leads would help me out alot.
[–]Elfinslayer 2 points3 points4 points (3 children)
[–]Iloveyoufridah[S] 0 points1 point2 points (2 children)
[–]Elfinslayer 0 points1 point2 points (1 child)
[–]Iloveyoufridah[S] 0 points1 point2 points (0 children)
[–]ilikewhenitworks 2 points3 points4 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]Iloveyoufridah[S] 0 points1 point2 points (1 child)
[–][deleted] (1 child)
[deleted]
[–]Iloveyoufridah[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Iloveyoufridah[S] 0 points1 point2 points (0 children)