Skip to content

Instantly share code, notes, and snippets.

@AmauryLugdu
Last active November 28, 2019 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmauryLugdu/1580011c102273660e93b420dccc92a4 to your computer and use it in GitHub Desktop.
Save AmauryLugdu/1580011c102273660e93b420dccc92a4 to your computer and use it in GitHub Desktop.
Express 2 - Express, SQL-MySQL, Postman
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.get('/api/movie', (req, res) => {
// connection to the database, and selection of employees
connection.query('SELECT * from movie', (err, results) => {
console.log(err)
if (err) {
// If an error has occurred, then the user is informed of the error
res.status(500).send('Erreur lors de la récupération des films');
} else {
// If everything went well, we send the result of the SQL query as JSON.
res.json(results);
}
});
});
app.get('/api/movie/name', (req, res) => {
// connection to the database, and selection of employees
connection.query('SELECT name from movie', (err, results) => {
console.log(err)
if (err) {
// If an error has occurred, then the user is informed of the error
res.status(500).send('Erreur lors de la récupération des films');
} else {
// If everything went well, we send the result of the SQL query as JSON.
res.json(results);
}
});
});
app.listen(port, err => {
if (err) {
throw new Error("Une erreur vient de se produire...");
};
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