Skip to content

Instantly share code, notes, and snippets.

@juliaheller
Last active March 14, 2020 21:00
Show Gist options
  • Select an option

  • Save juliaheller/977dbf3690b7aa5a5bb990b8731cb8ea to your computer and use it in GitHub Desktop.

Select an option

Save juliaheller/977dbf3690b7aa5a5bb990b8731cb8ea to your computer and use it in GitHub Desktop.
Express 1 - Discover Express
const express = require("express");
const app = express();
const port = 3008;
app.get("/", (request, response) => {
response.send("You are on the Homepage");
});
app.get("/api/movies", (request, response) => {
response.send("All films");
});
app.get("/api/movies/:movie_id", (request, response) => {
var movie_id = request.params.movie_id;
response.json({ id: movie_id }); //JSON object
});
app.get("/api/employee", (request, response) => {
if (request.query) {
var name = request.query.name;
response.status(404).send("Unable to retrieve employee");
} 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