CLiNTPELiX
5/17/2019 - 2:00 PM

index.js

const express = require("express");
const connection = require("./conf");
const app = express();
const port = 3000;

app.get("/api/movies", (req, res) => {
  connection.query("SELECT * from movie", (error, results) => {
    if (error) {
      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) {
            res.status(500).send('Erreur lors de la récupération des noms des films.')
        } else { res.json(results); }
    });
});

app.listen(port, err => { 
  if (err) {
    throw new Error("Something bad happened...");
  }

  console.log(`Server is listening on ${port}`);
});