Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Last active March 8, 2021 14:57
Show Gist options
  • Save gorkamu/58871619f7237abb87be797c6d703943 to your computer and use it in GitHub Desktop.
Save gorkamu/58871619f7237abb87be797c6d703943 to your computer and use it in GitHub Desktop.
Ejemplo de método DELETE en una API REST con Node.js
function deleteAlbum(req, res){
var albumId = req.params.id;
Album.findById(albumId, function(err, album){
if(err){
res.status(500).send({message: 'Error 500 al devolver el album'});
}else{
if(album){
album.remove(err => {
if(err){
res.status(500).send({message: 'Error 500 al borrar el album'});
}else{
res.status(200).send({message:'El album se ha borrado'});
}
});
}else{
res.status(400).send({message:'No hay album'});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment