Skip to content

Instantly share code, notes, and snippets.

@justinehell
Created September 11, 2020 09:54
Show Gist options
  • Save justinehell/386472e7023a80dfc5a6d23a3ad436e3 to your computer and use it in GitHub Desktop.
Save justinehell/386472e7023a80dfc5a6d23a3ad436e3 to your computer and use it in GitHub Desktop.
Express 1 - Découverte d'Express
const express = require("express");
const app = express();
const port = 3000;
app.get(`/api/movies`, (request, response) => {
response.send("Récupération de tous les films");
});
app.get(`/api/movies/:id`, (request, response) => {
response.json({ id: request.params.id });
});
app.get(`/api/employee`, (request, response) => {
if (request.query.name) {
response
.status(404)
.send(`Impossible de récupérer l'employé ${request.query.name}`);
} else {
response.sendStatus(304);
}
});
app.listen(port, (err) => {
if (err) {
throw new Error("Something bad happened...");
}
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