Node.js HTTP - module
Voorbeeld
Skep 'n bediener wat op poort 8080 van jou rekenaar luister.
Wanneer toegang tot poort 8080 verkry word, skryf "Hallo Wêreld!" terug as 'n antwoord:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello
World!');
res.end();
}).listen(8080);
Definisie en gebruik
Die HTTP-module bied 'n manier om Node.js-data oor HTTP (Hyper Text Transfer Protocol) oor te dra.
Sintaksis
Die sintaksis om die HTTP-module in jou toepassing in te sluit:
var http = require('http');
HTTP-eienskappe en -metodes
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 |