Add Express hello world example

This commit is contained in:
Tomas Krejci 2026-06-11 17:32:37 +02:00
parent 59bdabc012
commit b84e183651
6 changed files with 1716 additions and 0 deletions

View File

@ -0,0 +1,6 @@
{
"endOfLine": "lf",
"useTabs": true,
"printWidth": 120,
"tabWidth": 4
}

View 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"] },
]);

View File

@ -0,0 +1,5 @@
### Plain-text response
GET http://localhost:3000/hello-world
### JSON response
GET http://localhost:3000/hello-world-json

View 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}`);
});

File diff suppressed because it is too large Load Diff

View 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"
}
}