Skip to content

Instantly share code, notes, and snippets.

@dragonslayer77
Last active May 23, 2019 08:49
Show Gist options
  • Save dragonslayer77/b40f99f7cd84d2252067ece25251b01b to your computer and use it in GitHub Desktop.
Save dragonslayer77/b40f99f7cd84d2252067ece25251b01b to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./db');
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.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 editing an 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