Node

NODE http 모듈

테라시아 2024. 12. 8. 20:43

http 모듈
    - HTTP Protocol을 구현할 수 있는
      Node.js의 가장 기본적인 웹 모듈
    - HTTP Web Server 및 Client를 생성하는 모든 기능 담당
    - 보유 객체
        server
        response
        request

 

var http = require('http');

var options = {
    host: 'localhost',
    port: '10002',
    path: '/index.html'
};

// Callback Function
var callback = function(res){
    var content = '';
    res.on('data', function(data){
        content += data;
    });

    res.on('end', function(){
        console.log("Data Received");
        console.log(content);
    }); 
}

var request = http.request(options, callback);
request.end();

'Node' 카테고리의 다른 글

NODE 개념  (1) 2024.12.08