Skip to content

Instantly share code, notes, and snippets.

@justinehell
Last active September 13, 2020 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinehell/564fa39af18327704b340f60915066f1 to your computer and use it in GitHub Desktop.
Save justinehell/564fa39af18327704b340f60915066f1 to your computer and use it in GitHub Desktop.
Express 4 - Méthode PUT et modification de données
const express = require("express");
const app = express();
const port = 3000;
const connection = require("./conf");
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.put("/api/movies/:id", (req, res) => {
const idMovie = req.params.id;
const formData = req.body;
connection.query(
"UPDATE movie SET ? WHERE id = ?",
[formData, idMovie],
(err) => {
if (err) {
console.log(err);
res.status(500).send("Error when modifying a movie");
} 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