嗨,Node.js

2011-03-19 18:21

嗨,Node.js

by 子非鱼

at 2011-03-19 10:21:00

original http://ilstar.blogbus.com/logs/109689156.html

什么是Node.js
  简单来讲,通过Node.js,我们可以像使用Ruby, Python一样编写Server端的程序。

安装
  brew install node # mac
  或者可以在 http://nodejs.org/#download 下载源代码进行安装

安装npm
  curl http://npmjs.org/install.sh | sudo sh
  不是很精确的说,npm相对于Node.js就像gem相对于Ruby一样,使用它可以安装很多的插件,这里有一个站点可以搜索 http://search.npmjs.org/

Hello World

1
2
3
4
5
6
var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200, {'Content-type': 'text/plain'});
  res.end('Hello world!\n');
}).listen(8124, '127.0.0.1');

  将上面代码写入到文件hello.js中,通过如下命令启动服务

    node hello.js

  用浏览器打开 http://127.0.0.1:8124 即可看到输出的 Hello World!

其他资源

下面分别是两个博客里的文章系列,写的不错,值得参考一下。



博客大巴,你的个人传媒早班车


收藏到:Del.icio.us