Last active
November 28, 2019 08:11
-
-
Save AmauryLugdu/1580011c102273660e93b420dccc92a4 to your computer and use it in GitHub Desktop.
Express 2 - Express, SQL-MySQL, Postman
This file contains 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; | |
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