SHARE
TWEET

Untitled

a guest May 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const app = express();
  3. const port = 3000;
  4. const connection = require('./conf');
  5.  
  6. app.get('/api/movies', (req, res) => {
  7.     connection.query('SELECT * from movies', (err, results) => {
  8.         if(err) {
  9.             res.status(500).send('Erreur lors de la récupération des films');
  10.         } else {
  11.             res.json(results);
  12.         }
  13.     })
  14. });
  15.  
  16. app.get('/api/movies/names', (req, res) => {
  17.     connection.query('SELECT name from movies', (err, results) => {
  18.         if(err) {
  19.             res.status(500).send('Erreur lors de la récupération des noms');
  20.         } else {
  21.             res.json(results);
  22.         }
  23.     })
  24. })
  25.  
  26.  
  27. app.listen(port, (err) => {
  28.     if(err) {
  29.         throw new Error('Something bad happened...');
  30.     }
  31.     console.log(`Server is listening on ${port}`);
  32. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top