// Delete a candidate app.delete('/api/candidate/:id', (req, res) => { const sql = `DELETE FROM candidates WHERE id = ?`; const params = [req.params.id]; db.query(sql, params, (err, result) => { if (err) { res.statusMessage(400).json({ error: res.message }); } else if (!result.affectedRows) { res.json({ message: 'Candidate not found' }); } else { res.json({ message: 'deleted', changes: result.affectedRows, id: req.params.id }); } }); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter