现在的位置: 首页 > 综合 > 正文

Node.js——梗概

2013年05月16日 ⁄ 综合 ⁄ 共 376字 ⁄ 字号 评论关闭

一个用Node写成的web服务器,返回“Hello World”:

 

var http = require('http');

http.createServer(function(request, response){

response.writeHead(200, {'Content-Type':'text/plain'});

response.end('Hello World/n');

}).listen(8124)

 

console.log('Server running at http://127.0.0.1:8124/');

 

要运行这个服务器,首先将这些代码保存在example.js中,然后使用node程序执行它

 

node example.js

Server running at http://127.0.0.1:8124/

 

在本文档中的所有的例子都可以使用类似的方法运行。

抱歉!评论已关闭.