標準HTTPモジュールを使った簡単なHTTPサーバのサンプルコード
HTTPクライアントに比べると、簡単なHTTPサーバをたてたいと思うことは少ないが、
今回たまたまたてたくなったので調べてみた。
HTTP サーバ
require('http').createServer(function (req, res) { res.writeHead(200, {'Content-Type' : 'text/plain'}); res.end('Hello Node.js'); }).listen('5000', '127.0.0.1'); console.log('start server. open http://127.0.0.1:5000');
http://127.0.0.1:5000を表示すると、Hello Node.jsと表示される。