Created
June 7, 2019 11:27
-
-
Save evadav/7ab3db55089b8457ebe59c41b88ec81a to your computer and use it in GitHub Desktop.
Quest_Express_4
This file contains hidden or 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 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