---恢复内容开始---
nodejs的安装请参考官网:https://github.com/joyent/node/wiki/Installation
第一 小试牛刀
在服务器的根目录创建server.js
//请求(require)Node.js自带的http模块 并且将其赋值给http
var http = require("http");
//调用http的createServer函数,这个函数返回一个对象。这个对象有一个listen方法 此方法接收一个数值参数 用来指定服务器端口号
//看到里面的function没有 这个可是高级货啊 在js里面可以进行函数的传递 并且这里使用的是匿名函数。
http.createServer(function(reueset , response){
response.writeHead(200, {"Content-Type" : "text/plain"});
response.write("hello world");
response.end();
}).listen(8888);
运行node server.js
然后在浏览器里面访问localhost:8888 你会看到如下图:
原文:http://www.cnblogs.com/greenboy/p/4537517.html