Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created February 14, 2020 10:54
Show Gist options
  • Save bastienapp/0029e17e0aca61536980357f75f39454 to your computer and use it in GitHub Desktop.
Save bastienapp/0029e17e0aca61536980357f75f39454 to your computer and use it in GitHub Desktop.
Express quest 3
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
console.log(`Server is listening on ${port}`);
});
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/movies', (req, res) => {
const datas = req.body;
connection.query('INSERT INTO movie SET ?', datas, (err, results) => {
if (err) {
console.error(err);
res.status(500).send("Erreur lors de la sauvegarde d'un film");
} else {
res.sendStatus(200);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment