Skip to content

Instantly share code, notes, and snippets.

@dragonslayer77
Created May 23, 2019 09:12
Show Gist options
  • Save dragonslayer77/40749952bc1df4fb9c343364d4a1497c to your computer and use it in GitHub Desktop.
Save dragonslayer77/40749952bc1df4fb9c343364d4a1497c 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');
// Support JSON-encoded bodies
app.use(bodyParser.json());
// Support URL-encoded bodies
app.use(bodyParser.urlencoded({
extended: true
}));
app.delete('/api/movies/:id', (req, res) => {
const idMovie = req.params.id;
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 a movie");
} else {
// If everything went well, we send a status "ok".
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