ccdp10003-project01/index.js

24 lines
532 B
JavaScript
Raw Normal View History

2023-04-18 01:40:26 +10:00
import { createServer } from "http";
import { readFile } from "fs/promises";
const hostname = "127.0.0.1";
const port = 3000;
const server = createServer((req, res) => {
readFile("index.html")
.then((contents) => {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(contents);
})
.catch((err) => {
res.writeHead(500);
res.end(err);
return;
});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});