49 thoughts on “Node.js Blog App REST API with MongoDB”

  1. dear sir your backend api is tomuch difficult.. i make new api update and delete… and working…plz make samll and short code…. check my api code

    //delete api code and working
    router.delete("/:id", async (req, res) => {

    const result = await Post.deleteOne({_id: req.params.id});

    res.send(result);

    });

    //update Api working in your project…

    router.put("/:id", async (req,res) =>{

    const result = await Post.updateOne(

    {_id: req.params.id},

    {$set: req.body}

    )

    res.send(result)

    })

    Reply
  2. Very nice way of explaining. Would had been the perfect node tutorial if it had the comments feature as well. Nonetheless keep up the good work sir. Love from Pakistan.

    Reply
  3. 10:00 The useCreateIndex option has been deprecated for a while and removed as of the Mongoose 6 release per No More Deprecation Warning Options:

    useNewUrlParser , useUnifiedTopology , useFindAndModify , and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser , useUnifiedTopology , and useCreateIndex are true , and useFindAndModify is false .

    Reply
  4. {

    "errors": {

    "username": {

    "name": "ValidatorError",

    "message": "Path `username` is required.",

    "properties": {

    "message": "Path `username` is required.",

    "type": "required",

    "path": "username"

    },

    "kind": "required",

    "path": "username"

    },

    "email": {

    "name": "ValidatorError",

    "message": "Path `email` is required.",

    "properties": {

    "message": "Path `email` is required.",

    "type": "required",

    "path": "email"

    },

    "kind": "required",

    "path": "email"

    },

    "password": {

    "name": "ValidatorError",

    "message": "Path `password` is required.",

    "properties": {

    "message": "Path `password` is required.",

    "type": "required",

    "path": "password"

    },

    "kind": "required",

    "path": "password"

    }

    },

    "_message": "Users validation failed",

    "name": "ValidationError",

    "message": "Users validation failed: username: Path `username` is required., email: Path `email` is required., password: Path `password` is required."

    }
    i got the error in 26:27

    Reply
  5. I wrote the exact code that you wrote but when I was testing the register api it was showing error even after using express.json(). Can anyone give me any solution. I was using thunder client for the testing.

    Reply
  6. Yeah, finally complete this part. Thanks a lot, Lama 先生(sensei). Some parts were a bit difficult and as of April 2023, some parts of the code didn't work properly. So if anyone gets stuck, can see the other comments for solving. Hope can complete the last part of the series properly.

    Reply
  7. Hello Lama Dev, I have been following through your tutorial and I must acknowledge that your method of instructing is topnotch. Thank you so much for the outstanding content you are giving out.

    Reply
  8. Around 34:00:00 I faced errors while trying wrong credentials multiple times in a row.
    "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client".
    I had to change the login route code to this, notice the use of return:
    router.post('/login', async (req, res) => {
    try {
    const user = await User.findOne({ username: req.body.username });
    if (!user) {
    res.status(400).json('Wrong credentials!');
    return;
    }
    const validated = await bcrypt.compare(req.body.password, user.password);
    if (!validated) {
    res.status(400).json('Wrong credentials!');
    return;
    }
    const { password, …others } = user._doc;
    res.status(200).json(others);
    } catch (err) {
    res.status(500).json(err);
    }
    });
    Hope this helps someone else 🚀

    Reply
  9. Did anyone got the Solution ? of why we are getting stucked on 26:27 , after sending request to postman, there is no response by the postman, and after some time it shoes the response timeout error , if anybody can help, I have gone through the code, few times by know and i guess it seems perfect as there is no error in my VS code console too , but the postman is not responsing, if anyone can help ..thanks

    Reply

Leave a comment