1. http 모듈 살펴보기
const http = require("http");
console.log(http.STATUS_CODES);
console.log(http.METHODS);
2. 간단한 서버 만들어보기
const http = require("http");
const server = http.createServer((req, res) => {
console.log("Server On...");
console.log(req.headers);
console.log(req.httpVersion);
console.log(req.method);
console.log(req.url);
res.write("Hello");
res.end();
});
server.listen(8080);
3. 라우팅
const http = require("http");
const server = http.createServer((req, res) => {
if (req.url === "/") {
res.write("HOME");
} else if (req.url === "/test") {
res.write("TEST");
} else {
res.write("NOT FOUND");
}
res.end();
});
server.listen(8080);