首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

Ubuntu上Node.js的Hello World

2012-11-22 
Ubuntu下Node.js的Hello World近来Node.js很火,于是Hello World一下。Ubuntu 11.10 安装Node.js的方法,需要

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/

热点排行