Add Express hello world example
This commit is contained in:
parent
59bdabc012
commit
b84e183651
6
lecture_3/hello-world-express/.prettierrc.json
Normal file
6
lecture_3/hello-world-express/.prettierrc.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"endOfLine": "lf",
|
||||||
|
"useTabs": true,
|
||||||
|
"printWidth": 120,
|
||||||
|
"tabWidth": 4
|
||||||
|
}
|
||||||
24
lecture_3/hello-world-express/eslint.config.js
Normal file
24
lecture_3/hello-world-express/eslint.config.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import json from "@eslint/json";
|
||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{
|
||||||
|
ignores: ["node_modules/**", "package-lock.json"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["**/*.{js,mjs,cjs}"],
|
||||||
|
plugins: { js },
|
||||||
|
extends: ["js/recommended"],
|
||||||
|
languageOptions: { globals: globals.node, ecmaVersion: 2025 },
|
||||||
|
rules: {
|
||||||
|
indent: ["error", "tab"],
|
||||||
|
"linebreak-style": ["error", "unix"],
|
||||||
|
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
||||||
|
quotes: ["error", "double"],
|
||||||
|
semi: ["error", "always"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ files: ["**/*.json"], plugins: { json }, language: "json/json", extends: ["json/recommended"] },
|
||||||
|
]);
|
||||||
5
lecture_3/hello-world-express/hello-world.http
Normal file
5
lecture_3/hello-world-express/hello-world.http
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
### Plain-text response
|
||||||
|
GET http://localhost:3000/hello-world
|
||||||
|
|
||||||
|
### JSON response
|
||||||
|
GET http://localhost:3000/hello-world-json
|
||||||
21
lecture_3/hello-world-express/index.js
Normal file
21
lecture_3/hello-world-express/index.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
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}`);
|
||||||
|
});
|
||||||
1639
lecture_3/hello-world-express/package-lock.json
generated
Normal file
1639
lecture_3/hello-world-express/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
lecture_3/hello-world-express/package.json
Normal file
21
lecture_3/hello-world-express/package.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "hello-world-express",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"check": "npm run lint && prettier --check ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^5.1.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
|
"@eslint/json": "^1.2.0",
|
||||||
|
"eslint": "^10.0.0",
|
||||||
|
"globals": "^17.4.0",
|
||||||
|
"prettier": "^3.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user