{ res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello!"); }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));"> { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello!"); }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));"> { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello!"); }); server.listen(PORT, () => console.log(`Listening on port ${PORT}`));">
const http = require("http");
const PORT = 3000;
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello!");
});
server.listen(PORT, () => console.log(`Listening on port ${PORT}`));
<aside> 💡
http.createServer(*requestListener*);
</aside>
http.createServer()
메소드는 server 객체를 생성합니다.server.on('request', 콜백 함수);
server.listen()
=> 서버 실행, server.close()
=> 서버 종료server.on('request', 콜백 함수)
, server.on('connection', 콜백 함수)
...(close, upgrade...)req(request)
, res(response)
객체는 노드가 전달해줍니다.