Last active
December 7, 2019 12:00
-
-
Save rriamarria/e8a7f8ddf9cf74528dc0565d11e23b5a to your computer and use it in GitHub Desktop.
ODYSSEY_EXPRESS_DELETE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mysql = require('mysql'); | |
const connection = mysql.createConnection({ | |
host: 'localhost', | |
user: 'root', | |
password: process.env['SQLPASSWORD'], | |
database: 'my_db', | |
}) | |
module.exports = connection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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