读书人

Ubuntu上Node.js的Hello World

发布时间: 2012-11-22 00:16:41 作者: rapoo

Ubuntu下Node.js的Hello World
近来Node.js很火,于是Hello World一下。
Ubuntu 11.10 安装Node.js的方法,需要的朋友可以参考下。
1、安装依赖包:

sudo apt-get install g++ curl libssl-dev apache2-utils

2、若git未安装的话,安装git:
sudo apt-get install git

3、安装git后,下载源码:
sudo git clone git://github.com/ry/node.git 

4、然后转到下载后node文件夹下,编译安装
./configure make sudo make install 

5、然后测试代码:
编写如下小程序,命名为example.js,保存在node文件夹下。 
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World Node.js'); }).listen(8030, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8030/'); 

6、然后Terminal下,执行:
node example.js

7、浏览器地址栏:http://127.0.0.1:8030/

读书人网 >JavaScript

热点推荐