Created
June 5, 2020 16:28
-
-
Save clrko/44b8b5f5d3cf882540d7e11fa6c95572 to your computer and use it in GitHub Desktop.
Quest8_node_express_delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const connection = require('./conf'); | |
const app = express(); | |
const port = 8000; | |
app.use(express.json()); | |
app.use(express.urlencoded({ | |
extended: true | |
})); | |
app.delete('/api/movies/:id', (req, res) => { | |
const idMovie = req.params.id; | |
connection.query('DELETE FROM movie WHERE id = ?', [idMovie], err => { | |
if (err) { | |
console.log(err); | |
res.status(500).send("Erreur lors de la suppression d'un film"); | |
} else { | |
res.sendStatus(200); | |
} | |
}); | |
}); | |
app.listen(port, (err) => { | |
if (err) { | |
throw new Error('Something bad happened...'); | |
} | |
console.log(`Server is listening on ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment