Skip to content

Instantly share code, notes, and snippets.

@evadav
Created June 7, 2019 11:27
Show Gist options
  • Save evadav/7ab3db55089b8457ebe59c41b88ec81a to your computer and use it in GitHub Desktop.
Save evadav/7ab3db55089b8457ebe59c41b88ec81a to your computer and use it in GitHub Desktop.
Quest_Express_4
const express = require('express');
const app = express();
const port = 3000;
// para importar la cofiguración de la BD
const connection = require('./conf');
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/movie/:id', (req, res) => {
console.log("PUT /api/movie", req.body)
const idMovie = req.params.id;
const formData = req.body;
connection.query('UPDATE movie SET ? WHERE id = ?', [formData, idMovie], err => {
if (err) {
// If an error has occurred, then the user is informed of the error
console.log(err);
res.status(500).send("Error editing a movie");
} else {
// If everything went well, we send a status "ok".
res.sendStatus(200);
}
});
});
app.listen(port, function() {
// 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