1.Node的安装参考
:http://jingyan.baidu.com/article/b0b63dbfca599a4a483070a5.html
注意:
npm:node Package Manager虽然在安装node时候就已经安装了,但是应该先在命令行中,进行更新: npm install npm –g
然后才能运行:npm –v;
2.入门可以参考:http://www.runoob.com/nodejs/nodejs-tutorial.html
Helloworld 程序代码:
var http = require('http');
http.createServer(function (request,response) {
//发送 HTTP 头部
//HTTP 状态值: 200 : OK
//内容类型: text/plain
response.writeHead(200,{'Content-Type': 'text/plain'});
//发送响应数据 "Hello World"
response.end('HelloWorld\n');
}).listen(8888);
// 终端打印如下信息
console.log('Server running athttp://127.0.0.1:8888/');
以上代码我们完成了一个可以工作的 HTTP 服务器。
使用 node 命令执行以上的代码:
node server.js
Server running at http://127.0.0.1:8888/
Cmd :run
接下来,打开浏览器访问 http://127.0.0.1:8888/,你会看到一个写着"Hello World"的网页