Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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}`);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement