安装Node.js [2]
Step 1. 到nodejs.org上面直接下载nodejs的源码包node-v0.10.26.tar.gz,或者
>> wget http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz
Step 2. 解压
>> tar -zxvf node-v0.10.26.tar.gz
Step 3. 配置
>> ./configure
或指定安装路径
>> ./configure --prefix=/usr/local/node/0.10.26
Step 4. 安装
>> make all
>> make install
Step 5. 倘若在配置(Step 3)参数中指定了--prefix参赛,最好在环境变量中加入些信息。
>> vi /etc/profile
添加
export NODE_HOME=/usr/local/node/0.10.26
export PATH=$NODE_HOME/bin:$PATH
保存退出后执行如下命令,使profile生效
>> source /etc/profile
Step 6. 测试
>> node -h
注:如果要用nvm安装node.js,可参照文章[1].
安装Express [1]
>> npm install -g express
安装socket.io
>> cd ~
>> npm install -g node-gyp
>> npm install socket.io
另外,[1]中带有关于socket.io的例子,测试的时候客户端没有连接上socket,提示信息:
debug - served static content /socket.io.js
文章中讨论了这一问题,关键代码如下
app.configure(function() { app.use(express.static(__dirname + '/public')); ...... });
原文
[1] https://www.digitalocean.com/community/articles/how-to-install-express-a-node-js-framework-and-set-up-socket-io-on-a-vps
[2] http://blog.youkuaiyun.com/bushizhuanjia/article/details/7915358
[3] http://stackoverflow.com/questions/10191048/socket-io-js-not-found