From e60c281162be668a460b85ee9f73e2ab613f5a4f Mon Sep 17 00:00:00 2001 From: abhishektiwari003 Date: Tue, 17 Mar 2026 14:12:10 +0530 Subject: [PATCH] hello --- index.html | 29 +++++++++++++++++++++++++++++ package.json | 14 ++++++++++++++ server.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 index.html create mode 100644 package.json create mode 100644 server.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..464aed7 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + + Hello World + + + +

Hello World

+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..3663d73 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "helloworldpage", + "private": true, + "version": "1.0.0", + "description": "Simple Hello World page", + "main": "server.js", + "scripts": { + "start": "node server.js", + "dev": "node server.js" + }, + "engines": { + "node": ">=18" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..b1f4dae --- /dev/null +++ b/server.js @@ -0,0 +1,39 @@ +const http = require("node:http"); +const fs = require("node:fs"); +const path = require("node:path"); + +const PORT = Number.parseInt(process.env.PORT ?? "8080", 10) || 8080; +const INDEX_PATH = path.join(__dirname, "index.html"); + +const server = http.createServer((req, res) => { + if (req.method !== "GET") { + res.writeHead(405, { "Content-Type": "text/plain; charset=utf-8" }); + res.end("Method Not Allowed"); + return; + } + + if (req.url !== "/" && req.url !== "/index.html") { + res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }); + res.end("Not Found"); + return; + } + + fs.readFile(INDEX_PATH, (err, data) => { + if (err) { + res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" }); + res.end("Failed to read index.html"); + return; + } + + res.writeHead(200, { + "Content-Type": "text/html; charset=utf-8", + "Cache-Control": "no-store", + }); + res.end(data); + }); +}); + +server.listen(PORT, "0.0.0.0", () => { + // eslint-disable-next-line no-console + console.log(`Server running on http://0.0.0.0:${PORT}`); +});