我的第一个Node.js
1,先在http://nodejs.org/下载node-v0.6.6.msi,马上安装吧!
2.
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
保存为hello.js
3,
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>node D:/hello.js
4,
Server running at http://127.0.0.1:1337/
如上显示就说明对了。这个时候(不要关闭cmd),在浏览器里面输入http://127.0.0.1:1337/,就看到的网页源文件是:Hello World
OK! Over!