Last active
February 14, 2020 13:07
-
-
Save bastienapp/7f581bfbb87ae001f7a5bc9b39d30323 to your computer and use it in GitHub Desktop.
Express 2
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; | |
| const connection = require('./conf'); | |
| app.listen(port, (err) => { | |
| if (err) { | |
| throw new Error('Something bad happened...'); | |
| } | |
| console.log(`Server is listening on ${port}`); | |
| }); | |
| app.get('/api/movies', (req, res) => { | |
| connection.query('SELECT * from movie', (err, results) => { | |
| if (err) { | |
| console.error(err); | |
| res.status(500).send('Erreur lors de la récupération des films'); | |
| } else { | |
| res.json(results); | |
| } | |
| }); | |
| }); | |
| app.get('/api/movies/names', (req, res) => { | |
| connection.query('SELECT name from movie', (err, results) => { | |
| if (err) { | |
| console.error(err); | |
| res.status(500).send('Erreur lors de la récupération des noms de films'); | |
| } else { | |
| res.json(results); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment