ウェブサーバー作る
先ずはhttp要求とport設定を書き込む、そして、node.jsのウェブサーバー機能を組み立てる。app.js
var http = require('http');
http.createServer(function (request,response){
//requestとresponseにつてデータ転送文ここに書く
.
.
.
}).listen(8080)
テータ転送の基本の概念はブラウザからウェブサーバーにrequest請求を届く、request請求の中身はパケットですから、いろいろな転送データをここに入れる、反対の方向はresponse請求と言われる、response請求はウェブサーバーからブラウザにデータパケットを届いてブラウザの上にデータを表示する。

次はrequestとreponse文を試す、先ずはrequestの情報を表示して、node.jsサーバーはreponseの内容をブラウザで示す。
app.js
var http = require('http');
http.createServer(function (request,response){
console.log(request.url); //urlの情報
//writeHead関数の引数は一つ目はHTTP状態番号、二つ目は転送データ条件のオブジェクト
response.writeHead(200,{"Content-Type":"text/plain"});//200:ok data-type:plain
response.write('hello!!'); //表示する文字
response.end();//請求終わる
}).listen(8080);
urlはホームページ、favicon.icoはブラウザiconの情報。
terminal
$node app.js
/
/favicon.ico

他の例も試す。
app.js
var http = require('http');
http.createServer(function (request,response){
console.log(request.method); //HTTPのメソッド
//writeHead関数の引数は一つ目はHTTP状態番号、二つ目は転送データ条件のオブジェクト
response.writeHead(200,{"Content-Type":"html"}); //200:ok data-type:html
response.write('<h2>apple!!</h2>');
response.end();//請求終わる
}).listen(8080);
terminal
$node app.js
GET
GET
