Last active
February 14, 2020 13:05
-
-
Save bastienapp/fa9b4d0da2505e8b2c7dc1d8f6687851 to your computer and use it in GitHub Desktop.
Express quest 4
This file contains hidden or 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 app = express(); | |
| const port = 3000; | |
| const connection = require('./conf'); | |
| app.listen(port, (err) => { | |
| if (err) { | |
| throw new Error('Something bad happened...'); | |
| } | |
| console.log(`Server is listening on ${port}`); | |
| }); | |
| const bodyParser = require('body-parser'); | |
| // Support JSON-encoded bodies | |
| app.use(bodyParser.json()); | |
| // Support URL-encoded bodies | |
| app.use(bodyParser.urlencoded({ | |
| extended: true | |
| })); | |
| app.put('/api/movies/:id', (req, res) => { | |
| const id = req.params.id; | |
| const datas = req.body; | |
| connection.query('UPDATE movie SET ? WHERE id = ?', [datas, id], err => { | |
| if (err) { | |
| console.error(err); | |
| res.status(500).send("Erreur lors de la modification d'un film"); | |
| } else { | |
| res.sendStatus(200); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment