Last active
July 1, 2019 09:54
-
-
Save evadav/89224ab31e08e4b9d1792e76d9349b90 to your computer and use it in GitHub Desktop.
Quest_Express_3
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.post('/api/movie', (req, res) => { | |
// Data stored in req.body | |
console.log("POST /api/movie", req.body) | |
const formData = req.body; | |
connection.query('Insert into movie set ?', formData, (err, results) => { | |
// send a response to the client (step 4) | |
if (err) { | |
console.log(err); | |
res.status(500).send("Error saving a movie"); | |
} else { | |
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