1

以下は、Node.JS のほとんどの書籍に記載されている典型的な hello world の例です。

var http = require('http');
    http.createServer(function (req, res) {
    res.**writeHead**(200, {'Content-Type': 'text/plain'});
    res.**end**('Hello World\n');
    }).listen(8124, "127.0.0.1");

「require」を介してhtml機能がvar httpに入れられたことを理解できます。したがって、.createserver 関数はそのモジュールに記述され、コールバックのパラメーターとして無名関数が渡されます。しかし、「writehead」と「end」はどこで定義されていますか? それは正確には何ですか?

4

1 に答える 1

4

resクラスServerResponse http://nodejs.org/api/http.html#http_class_http_serverresponseのインスタンスです

于 2013-05-07T17:53:21.107 に答える