Hello Worldサーバ

概要

シンプルなWebサーバ


サンプル

sample02.js

// httpライブラリを読み込む
var http = require("http");
 
// サーバを生成して、受付
http.createServer(function(request, response) {
 
  console.log("Http Test Start");
 
  // ヘッダー出力
  response.writeHead(200, {"Content-Type": "text/plain"});
 
  // データ出力
  response.write("Hello World");
 
  // レスポンス終了
  response.end();
 
  console.log("Http Test End");
 
}).listen(8888);
 
 
 

実行

コマンド

D:\Tools\Works\nodejs_test\sample02>node sample02.js
Http Test Start
Http Test End
Http Test Start
Http Test End
 
 

画面




最終更新:2013年03月25日 23:54