Skip to content

Instantly share code, notes, and snippets.

@rriamarria
Last active December 7, 2019 12:00
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 rriamarria/e8a7f8ddf9cf74528dc0565d11e23b5a to your computer and use it in GitHub Desktop.
Save rriamarria/e8a7f8ddf9cf74528dc0565d11e23b5a to your computer and use it in GitHub Desktop.
ODYSSEY_EXPRESS_DELETE
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: process.env['SQLPASSWORD'],
database: 'my_db',
})
module.exports = connection;
const express = require('express');
const app = express();
const connection = require('./conf');
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
app.delete('/api/movies/:id', (req, res) => {
const movieId = req.params.id;
connection.query('DELETE FROM movie WHERE id = ?', [movieId], err => {
if (err) {
res.status(500).send(`Error deleting the movie: ${err}`);
} else {
res.status(200).send(`Movie with id ${movieId} successfully deleted from database.`)
}
});
});
app.listen(3000, (err) => {
if (err) {
throw new Error(`Something bad happened: ${err}`)
}
console.log(`Server is listening on ${3000}`);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment