Skip to content

Instantly share code, notes, and snippets.

@alyson-b69
Created September 8, 2020 08:51
Show Gist options
  • Save alyson-b69/0ec681667834b9cf193c129472cc8b90 to your computer and use it in GitHub Desktop.
Save alyson-b69/0ec681667834b9cf193c129472cc8b90 to your computer and use it in GitHub Desktop.
Express1
const express = require("express");
const { response } = require("express");
const app = express();
const port = 3000;
app.get("/", (request, response) => {
response.send("Bienvenue sur Express");
});
app.get("/api/movies", (req, res) => {
res.send("Récupération de tous les films");
});
app.get("/api/movies/:id", (req, res) => {
const id = req.params.id;
res.json({ id: id });
});
app.get("/api/employee", (req, res) => {
const name = req.query.name;
if (name) {
res.status(404).send(`Impossible de récupérer l'employé ${name}`);
} else {
res.sendStatus(304).end();
}
});
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