node.js入門示例

1、控制檯版 Hello World

編輯文件hello_world.js

        var sys = require("util");
	sys.puts("Hello world");

執行:node hello_world.js

結果:



2、網頁版Hello world

編譯文件 http_hello_world.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World - Node.js Work.
');
}).listen(5656, '127.0.0.1');
console.log('Server running at http://127.0.0.1:5656/');
執行: node http_hello_world.js

結果:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章