일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Linux rmdir
- linux background
- EC2 HTTP 호스팅
- Linux 디렉터리 역할
- Linux ls
- AWS EC2 서버 만들기
- Linux apt-get
- Logback
- EC2 Apache2
- javascript scope
- Linux cd
- Linux cat
- Linux 디렉터리 구조
- Linux oh my zsh
- Linux apt
- EC2 zsh
- Linux 디렉터리 명령어
- EC2 oh my zsh
- Linux 파일 관리 명령어
- Linux mkdir
- Navigation Pattern
- 자바스크립트 런타임
- JavaScript 실행 디버깅
- linux foreground
- javascript 정렬
- Linux pwd
- 자바스크립트 이벤트 루프
- HTTP Web Server
- 서버의 서비스 방식
- JavaScript EventLoop
Archives
- Today
- Total
HyunJun 기술 블로그
Node.js HTTP Module, Express 본문
728x90
반응형
1. 서버 모듈
- HTTP Module: 웹 서버를 만들기 위한, Node.js의 서버 모듈
- Express: 웹 서버를 만들기 위한 Node.js의 웹 프레임워크, 서버 모듈, HTTP Module보다 더 간편, 많은 기능
2. 코드 비교
1) HTTP Module
// http module.
const http = require("http");
const httpPort = 3000;
// HTTP Module Server
const httpModuleServer = http.createServer((req, res) => {
if (req.method === "GET" && req.url === "/http") {
res.writeHead(200, {
"Content-Type": "text/html",
});
res.end("http");
}
});
// 실행
httpModuleServer.listen(httpPort, () => {
console.log(`http server running at port ${httpPort}`);
});
2) Express Module (Framework)
// express web framework module.
const express = require("express");
const app = express();
const expressPort = 3000;
// Express Module Server
app.get("/express", function (req, res) {
res.send("express");
});
// 실행
app.listen(expressPort, function () {
console.log(`express running at ${expressPort}`);
});
기능이나 가독성, 편리함 등에서 Express가 깔끔함.
728x90
반응형
Comments