Created
June 5, 2019 09:43
-
-
Save brendaMan/059749e7767f5a68020f26b34e121906 to your computer and use it in GitHub Desktop.
Express 2 - Express, SQL - MySQL, Postman
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 connection = require('./conf'); | |
const express = require('express'); | |
const app = express(); | |
const port = 3000; | |
app.get('/api/movies', (req, res) => { | |
connection.query('SELECT * from movie', (err, results) => { | |
if (err) { | |
console.log(err) | |
res.status(500).send('Error lors de la récupération des movies'); | |
} else { | |
res.json(results); | |
} | |
}); | |
}); | |
app.get('/api/movies/name', (req, res) => { | |
connection.query('SELECT name from movie', (err, results) => { | |
if (err) { | |
res.status(500).send('Error lors de la récupération des movies'); | |
} else { | |
res.json(results); | |
} | |
}); | |
}) | |
app.listen(port, (err) => { | |
if(err) { | |
throw new Error('There is an error!') | |
} | |
console.log(`Im listening on ${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment