Created
October 28, 2022 09:09
-
-
Save Swendude/50c50150256433b39b4bc9cd1dfa81fd to your computer and use it in GitHub Desktop.
Kriztian's express assessment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { response } = require("express"); | |
const express = require("express"); | |
const app = express(); | |
const animals = require("./animals"); | |
app.get("/", (request, response) => { | |
response.send("Hello from Express server"); | |
}); | |
// HTML string | |
const document = `<html> | |
<head> | |
<title>Test page</title> | |
</head> | |
<body> | |
<h1>Hello World! i am here!</h1> | |
</body> | |
</html>`; | |
app.get("/message", (request, response) => { | |
response.send(document); | |
}); | |
// animal list | |
app.get("/animals", (request, response) => { | |
response.send(animals); | |
}); | |
// matching ID | |
app.get("/animals:/id", (request, response) => { | |
response.send(request.params.title); | |
}); | |
// food route | |
app.get("/animals/food/:food", (request, response) => { | |
response.send(request.params.food); | |
}); | |
const port = 4001; | |
app.listen(port, () => console.log(`Listening on ${port}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment