Friday 27 March 2020

Module.exports tips/ best practices

Hi folks,I am using NodeJS in tandem with express for my server and I have hit a problem.I am using module.exports as my methods, and I am trying to pass the ID from the client to the server to delete a specific document.The ID is being sent successfully, but I am struggling to pull that ID and pass it through the function.Route for the delete function (Server)router.delete('/RemoveDealDetails/:id', DealDet.RemoveDealDetails);Delete Function (Server)module.exports.RemoveDealDetails = router.delete('/:id', (req,res) => {DealDetails.findByIdAndRemove({_id:req.body.id}, (err,doc) => {if (!err) {console.log("RemoveDealDetails: " + doc);res.send(doc);} else {console.log("Error in DealDetails save, Find By ID and Remove : " + JSON.stringify(err, undefined, 2));}});RemoveDealDetails method (Client)console.log("Remove Details: " + _id);return this.http.delete(environment.apiBaseUrl + "/RemoveDealDetails" + \/${_id}\);``I am passing the ID through the URL.

Submitted March 27, 2020 at 02:16PM by wazzalk

No comments:

Post a Comment