const http = require("http"); const fs = require("fs").promises; const host = "localhost"; const port = 8080; const profileData = { name: "Toe Hlaing Win", age: "***", professional: "Web Developer", addres: "YGN ***", }; const server = http.createServer(function (req, res) { console.log("dir name", __dirname); if (req.url == "/") { fs.readFile(__dirname + "/welcome.html").then((content) => { res.setHeader("Content-Type", "text/html"); res.writeHead(200); res.end(content); }); } if (req.url == "/profile") { fs.readFile(__dirname + "/profile.html").then((content) => { res.setHeader("Content-Type", "text/html"); res.writeHead(200); res.end(content); }); } if (req.url == "/api/profile") { console.log("Reach Here ..."); console.log(typeof profileData); res.setHeader("Content-Type", "application/json"); res.writeHead(200); res.end(JSON.stringify(profileData)); } }); server.listen(port, host, () => { console.log("Server Runnin at " + host + ":" + port); });