Node.js HTTP 모듈
예시
컴퓨터의 포트 8080에서 수신 대기하는 서버를 만듭니다.
포트 8080에 액세스하면 "Hello World!"라고 작성하십시오. 응답으로 다시:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello
World!');
res.end();
}).listen(8080);
정의 및 사용
HTTP 모듈은 Node.js가 HTTP(Hyper Text Transfer Protocol)를 통해 데이터를 전송하도록 하는 방법을 제공합니다.
통사론
애플리케이션에 HTTP 모듈을 포함하기 위한 구문:
var http = require('http');
HTTP 속성 및 메서드
Method | Description |
---|---|
createClient() | Deprecated. Creates a HTTP client |
createServer() | Creates an HTTP server |
get() | Sets the method to GET, and returns an object containing the user's request |
globalAgent | Returns the HTTP Agent |
request() | Returns an object containing the user's request |