Skip to content Skip to sidebar Skip to footer

Node Mongo Rest Service Post

I have created a REST service using Node.js and MongoDB for using in one of my Android app. The get methods is working as expected when called from Android App. I am trying to buil

Solution 1:

To get the parameter from the route you need to use req.params, in your case req.params.uObject. Also common practice in JavaScript is to return early upon a condition being met.

app.post('/accounts/put/:uObject', function(req, res, next) {
    var username = req.params.uObject;

    db.collection('test').insert({
        "username": username
    }, function(err, docs) {
        if (err) {
            return res.send("There was some problem during insertions of linkes");
        }
        res.send("Fail");
    });

});

Post a Comment for "Node Mongo Rest Service Post"