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

node.js装配与使用

2012-11-05 
node.js安装与使用下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.Mac在Mac下,如果你喜欢用ho

node.js安装与使用

下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.

Mac

在Mac下,如果你喜欢用homebrew,那么只用一行就可以装好:

brew install node

否则,只能考虑手工安装了,步骤如下:

    安装Xcode 安装git 运行下面的命令行编译node.js
    git clone git://github.com/joyent/node.gitcd node./configuremakesudo make install

Ubuntu
    安装依赖包
    sudo apt-get install g++ curl libssl-dev apache2-utilssudo apt-get install git-core
    运行下面的命令行:
    git clone git://github.com/joyent/node.gitcd node./configuremakesudo make install

Windows

用cygwin来安装node,步骤如下:

    安装cygwin 在cygwin的目录下,运行setup.exe安装下面列表中的包devel → openssl devel → g++-gcc devel → make python → python devel → git 运行cygwin 运行下面的命令行:
    git clone git://github.com/joyent/node.gitcd node./configuremakesudo make install

Centos
yum install gcc-c++ openssl-develwget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gzcd ry-node-v0.3.3-0-g57544bac1./configuremakemake install
Hello Node.js!

写一段小程序例如hello_node.js来验证安装是否正确:

var http = require('http');http.createServer(function (req, res) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello Node.js\n');}).listen(8124, "127.0.0.1");console.log('Server running at http://127.0.0.1:8124/');

用node来运行这段代码

node hello_node.jsServer running at http://127.0.0.1:8124/

现在,用浏览器打开 http://127.0.0.1:8124/ , 应该能够看到一条好消息。

热点排行