MERN mongoDB collection is not updating and response doesnt sent

Viewed 67

I am new to MERN and im developing api for my react application. Im following a tutorial. I have created following code for testing purposes. But the response is not sent and mondoDB collection also not updating. database has connected.

const router = require("express").Router();
const User = require("../models/User");

//Register
router.get('/register', async(req, res) => {
     const user = await new User({
         username:"Kasun",
         email:"banchiyt@gmail.com",
         password:"kasun123"
     })
    await user.save();
    res.send("Ok");
});

module.exports = router;

what goes wrong here ? ?

1 Answers
router.get('/register', async(req, res) => {
     const user = new User({
         username:"Kasun",
         email:"banchiyt@gmail.com",
         password:"kasun123"
     })
    await user.save();
    res.send("Ok");
});

You had one await too much, if this does not work then plese post your node errors & User model.

Related