{ if (req.url === "/home") { res.statusCode = 200; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ a: "a", b: "b" })); } else if (req.url === "/about") { res.setHeader("Content-Type", "text/html"); res.write(""); res.write(""); res.write("

About Page

"); res.write(""); res.write(""); res.end(); } else { res.statusCode = 404; res.end(); } }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));"> { if (req.url === "/home") { res.statusCode = 200; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ a: "a", b: "b" })); } else if (req.url === "/about") { res.setHeader("Content-Type", "text/html"); res.write(""); res.write(""); res.write("

About Page

"); res.write(""); res.write(""); res.end(); } else { res.statusCode = 404; res.end(); } }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));"> { if (req.url === "/home") { res.statusCode = 200; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ a: "a", b: "b" })); } else if (req.url === "/about") { res.setHeader("Content-Type", "text/html"); res.write(""); res.write(""); res.write("

About Page

"); res.write(""); res.write(""); res.end(); } else { res.statusCode = 404; res.end(); } }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));">

Untitled

Untitled

Untitled

const http = require("http");

const PORT = 3000;

const server = http.createServer((req, res) => {
  if (req.url === "/home") {
    res.statusCode = 200;
    res.setHeader("Content-Type", "application/json");
    res.end(JSON.stringify({ a: "a", b: "b" }));
  } else if (req.url === "/about") {
    res.setHeader("Content-Type", "text/html");
    res.write("<html>");
    res.write("<body>");
    res.write("<h1>About Page</h1>");
    res.write("</body>");
    res.write("</html>");
    res.end();
  } else {
    res.statusCode = 404;
    res.end();
  }
});

server.listen(PORT, () => console.log(`Listening on port ${PORT}`));

스크린샷 2023-11-17 오후 1.37.06.png

스크린샷 2023-11-17 오후 1.37.20.png

스크린샷 2023-11-17 오후 1.37.35.png

스크린샷 2023-11-17 오후 1.37.52.png