Node.js- HTTP - Modul

❮ Eingebaute Module


Beispiel

Erstellen Sie einen Server, der Port 8080 Ihres Computers abhört.

Wenn auf Port 8080 zugegriffen wird, schreiben Sie "Hello World!" zurück als Antwort:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
  res.end();
}).listen(8080);

Definition und Verwendung

Das HTTP-Modul bietet eine Möglichkeit, Node.js dazu zu bringen, Daten über HTTP (Hyper Text Transfer Protocol) zu übertragen.


Syntax

Die Syntax zum Einbinden des HTTP-Moduls in Ihre Anwendung:

var http = require('http');

HTTP-Eigenschaften und -Methoden

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

❮ Eingebaute Module