Add optional name + docs (#25)

* Add optional name

* docs: add README.md with project documentation
This commit is contained in:
Rock
2025-12-02 14:09:31 +01:00
committed by GitHub
parent ca292d17f3
commit b4d021a548
7 changed files with 122 additions and 24 deletions

View File

@@ -1,5 +1,13 @@
function getGreeting() {
return 'Hello world';
function getGreeting(name) {
const greeting = `Hello world!`;
if (name) {
const wisher = `From ${name}`;
return `${greeting} ${wisher}`;
}
return greeting;
}
module.exports = { getGreeting };

View File

@@ -1,11 +1,19 @@
const express = require('express');
const { getGreeting } = require('./greeting');
const express = require("express");
const { getGreeting } = require("./greeting");
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/hello', (req, res) => {
res.send(getGreeting());
app.get("/hello/:name?", (req, res) => {
const name = req.params.name;
res.send(getGreeting(name));
});
app.post("/hello", (req, res) => {
const name = req.headers["x-name"];
res.send(getGreeting(name));
});
if (require.main === module) {