diff --git a/README.md b/README.md new file mode 100644 index 0000000..7510ad4 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Keyboard Learning Game + +Full-screen blue background. Whatever key you press shows up **BIG + BOLD** for kids to learn letters, numbers, and symbols. + +## Run + +### Option 1: Open directly + +Open `index.html` in your browser. + +### Option 2: Run a small server (recommended) + +```bash +npm start +``` + +Then open `http://localhost:8080`. diff --git a/index.html b/index.html new file mode 100644 index 0000000..49db796 --- /dev/null +++ b/index.html @@ -0,0 +1,224 @@ + + + + + + Keyboard Learning Game + + + + +
+

Press a key

+
+ Type any letter, number, or symbol on your keyboard (try A, 1, + !, @). +
+
+ + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..54c5b32 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "keyboard-learning-game", + "version": "1.0.0", + "private": true, + "description": "A simple keyboard learning game for kids.", + "type": "module", + "scripts": { + "start": "node server.js" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..5d76413 --- /dev/null +++ b/server.js @@ -0,0 +1,45 @@ +import http from "node:http"; +import { readFile } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; +import path from "node:path"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const port = process.env.PORT ? Number(process.env.PORT) : 8080; + +const server = http.createServer(async (req, res) => { + try { + const url = new URL( + req.url ?? "/", + `http://${req.headers.host ?? "localhost"}`, + ); + const pathname = url.pathname === "/" ? "/index.html" : url.pathname; + + // Only serve files from this folder; keep it intentionally simple. + const safePath = path.normalize(pathname).replace(/^(\.\.(\/|\\|$))+/, ""); + const filePath = path.join(__dirname, safePath); + + const data = await readFile(filePath); + const ext = path.extname(filePath).toLowerCase(); + + const contentType = + ext === ".html" + ? "text/html; charset=utf-8" + : ext === ".js" + ? "text/javascript; charset=utf-8" + : ext === ".css" + ? "text/css; charset=utf-8" + : "application/octet-stream"; + + res.writeHead(200, { "Content-Type": contentType }); + res.end(data); + } catch { + res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }); + res.end("Not found"); + } +}); + +server.listen(port, () => { + // Intentionally minimal output. + console.log(`Keyboard game running on http://localhost:${port}`); +});