Node.js Simple Web Server
下面是個簡單的Node Web Server範例,語意上為載入http模組之後,使用http模組建立server,並在回應部份寫入header為
'Content-Type': 'text/plain'並回傳http code=200等的資訊。 而最後因為Node.js繼承JavaScript的語法慣例,因此最後可以直接由server物件呼叫設定聽取8124 port開啓http web服務。
varhttp=require('http');
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124,"127.0.0.1");