Node.js HTTP မော်ဂျူး
ဥပမာ
သင့်ကွန်ပျူတာ၏ port 8080 တွင် နားထောင်နိုင်သော ဆာဗာတစ်ခုကို ဖန်တီးပါ။
port 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 module သည် Node.js ဒေတာလွှဲပြောင်းခြင်းကို HTTP (Hyper Text Transfer Protocol) မှတဆင့် ပြုလုပ်သည့်နည်းလမ်းကို ပံ့ပိုးပေးပါသည်။
အထားအသို
သင့်အပလီကေးရှင်းတွင် HTTP module ကိုထည့်သွင်းခြင်းအတွက် syntax-
var http = require('http');
HTTP Properties နှင့် Methods
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 |