how to get data from database & if data is not available then entered data stored in database in nodejs.
I have a code:
router.get('/pincode/:pincode', function (req, res) {
Pincode.find({
pincode: req.params.pincode
}, function (err, pincodes) {
if (pincodes == '') {
var pincodeData = new Pincode({
pincode: req.params.pincode,
country: req.body.country,
state: req.body.state,
district: req.body.district,
taluka: req.body.taluka,
city: req.body.city,
area: req.body.area
});
pincodeData.save(function (err, results) {
if (err) {
return err;
} else {
console.log("Got a response: ", results);
// console.log("data:"+body);
}
});
}
res.json(pincodes);
});
});
via Poonam
No comments:
Post a Comment