Skip to content

Instantly share code, notes, and snippets.

@evadav
Created June 7, 2019 11:39
Show Gist options
  • Save evadav/f8c617a884961a520c7992e194b9d4a6 to your computer and use it in GitHub Desktop.
Save evadav/f8c617a884961a520c7992e194b9d4a6 to your computer and use it in GitHub Desktop.
Quest_Express_5
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
}));
// DELETE
app.delete('/api/movie/:id', (req, res) => {
// Get the data sent
const idMovie = req.params.id;
// connection to the database, and insertion of the movie
connection.query('DELETE FROM movie WHERE id = ?', [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 deleting an 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