Friday, 4 September 2020

Code refuses to connect to mongodb and has shown no error

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 coderouter.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.

Submitted September 04, 2020 at 06:45PM by Iloveyoufridah

No comments:

Post a Comment