Advertisement
Lola_D

Express4

Jun 3rd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. const express = require('express')
  2. const connection = require('./conf')
  3. const app = express()
  4. const port = 8080
  5.  
  6. app.use(express.json())
  7. app.use(express.urlencoded({
  8.   extended: true
  9. }))
  10.  
  11. app.put('/api/movies/:id', (req, res) => {
  12.   const formData = req.body
  13.   const idMovie = req.params.id
  14.   connection.query('UPDATE movie SET ? WHERE id = ?', [formData, idMovie], err => {
  15.     if (err) {
  16.       res.status(500).send('Erreur lors de la modification d\'un film')
  17.    } else {
  18.      res.sendStatus(200)
  19.    }
  20.  })
  21. })
  22.  
  23. app.listen(port, (err) => {
  24.  if (err) {
  25.    throw new Error('Something bad happened...')
  26.  }
  27.  console.log(`Server is listening on ${port}`)
  28. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement