I have a function that recursively deletes nodes:
removeNode(data.toString())
function removeNode(node){
Item.findByIdAndDelete(node).then(()=>{
Item.find({parent: mongoose.Types.ObjectId(node)}).select('_id').then((nodes)=>{
nodes.forEach(n => {
removeNode(n._id)
});
})
})
}
I want to convert this function into a promise so I can use it like this:
removeNode(data.toString()).then(()=>{console.log('deletion complete')})
Any suggestions on how I can achieve this promisification would be highly appreciated!