I am working on a project. I am using Angular 2 as a front end and firebase as backend. TO access the data from Firebase i am using express. I am using REST methodology. Now all i am facing an issue here is to rest the data after i delete anything or update anything in the List. I am posting Delete and Update code. Please let me know whether i am doing any mistake or what.
router.route('/contacts/:id').get(function(req , res) { //Show contact based on ID which is passed as perameter var contactId = req.params.id; contactRef.child(contactId).once('value' , function(snapshot) { if(snapshot.exists()) { var contactVal = snapshot.val(); res.json(contactVal); } else { res.json({message : "Contact does not exist"}); } }) }).delete(function(req,res) { //Deletes the Contact based on the ID which we are passing as perameter var contactId = req.params.id; console.log(contactId); contactRef.child(contactId).remove(function(){ console.log("deleted") }); res.json({message : "Contact with contact id "+ contactId +" has been removed"}); }).put(function(req, res) { //Updates the contact based on ID passed in the perameter. var contactId = req.params.id; console.log(req.body); contactRef.child(contactId).update(); contactRef.child(contactId).once(req.body , function(snapshot) { // if(snapshot.exists()) { console.log("Contact Id" + contactId) var contactVal = snapshot.val(); res.json({"contact ID " : contactId} ); } else { res.json({message : "Contact does not exist"}); } }) }) This is the code i am using but not having any idea what to do. Please let me whether i am doing anything wrong then.
onearlier. but it was giving me async header error. So i am usingonce.