22 lines
569 B
JavaScript
22 lines
569 B
JavaScript
import express from "express";
|
|
|
|
const app = express();
|
|
const port = Number(process.env.PORT ?? 3000);
|
|
|
|
// Return a plain-text response for the simplest HTTP endpoint example.
|
|
app.get("/hello-world", (_request, response) => {
|
|
response.send("Hello world!");
|
|
});
|
|
|
|
// Return structured data and a value generated for each request.
|
|
app.get("/hello-world-json", (_request, response) => {
|
|
response.json({
|
|
message: "Hello world!",
|
|
serverTime: new Date().toISOString(),
|
|
});
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server is running at http://localhost:${port}`);
|
|
});
|