2015年3月3日 星期二

在 CentOS 下安裝 Node.js 模組

昨天安裝好 Node.js 後,嘗試了 http 庫,能很簡單地印出 HTTP 回應。在網上找到評論說「http 之於 connect,就如 connect 之於 express」,所以今天試試安裝 express。首先跳到安裝好 Node.js 的目錄:
[root@centos ~]# cd /usr/local/node-v0.12.0-linux-x64/
利用 npm 安裝 express:
[root@centos lib]# npm install express
express@4.12.2 node_modules/express
├── merge-descriptors@1.0.0
├── utils-merge@1.0.0
├── cookie-signature@1.0.6
├── methods@1.1.1
├── fresh@0.2.4
├── cookie@0.1.2
├── escape-html@1.0.1
├── range-parser@1.0.2
├── finalhandler@0.3.3
├── content-type@1.0.1
├── vary@1.0.0
├── parseurl@1.3.0
├── serve-static@1.9.1
├── content-disposition@0.5.0
├── path-to-regexp@0.1.3
├── depd@1.0.0
├── on-finished@2.2.0 (ee-first@1.1.0)
├── qs@2.3.3
├── debug@2.1.2 (ms@0.7.0)
├── proxy-addr@1.0.6 (forwarded@0.1.0, ipaddr.js@0.1.8)
├── send@0.12.1 (destroy@1.0.3, ms@0.7.0, mime@1.3.4)
├── accepts@1.2.4 (negotiator@0.5.1, mime-types@2.0.9)
├── etag@1.5.1 (crc@3.2.1)
└── type-is@1.6.0 (media-typer@0.3.0, mime-types@2.0.9)
完成,非常簡單。由於新版 express 已沒有包含 Cookie Parser,要特別自行安裝:
[root@centos node.js]# npm install cookie-parser
cookie-parser@1.3.4 node_modules/cookie-parser
├── cookie-signature@1.0.6
└── cookie@0.1.2
除了 express 之外,我還想試試 Socket 通訊,因此還安裝了 Socket.io:
[root@centos lib]# npm install socket.io
 
> ws@0.5.0 install /usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node: Finished
  COPY Release/bufferutil.node
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  SOLINK_MODULE(target) Release/obj.target/validation.node: Finished
  COPY Release/validation.node
make: Leaving directory `/usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'

> ws@0.4.31 install /usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
make: Leaving directory `/usr/local/node-v0.12.0-linux-x64/lib/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
socket.io@1.3.5 node_modules/socket.io
├── debug@2.1.0 (ms@0.6.2)
├── has-binary-data@0.1.3 (isarray@0.0.1)
├── socket.io-adapter@0.3.1 (object-keys@1.0.1, debug@1.0.2, socket.io-parser@2.2.2)
├── socket.io-parser@2.2.4 (isarray@0.0.1, debug@0.7.4, component-emitter@1.1.2, benchmark@1.0.0, json3@3.2.6)
├── engine.io@1.5.1 (base64id@0.1.0, debug@1.0.3, engine.io-parser@1.2.1, ws@0.5.0)
└── socket.io-client@1.3.5 (to-array@0.1.3, indexof@0.0.1, debug@0.7.4, component-bind@1.0.0, backo2@1.0.2, object-component@0.0.3, component-emitter@1.1.2, has-binary@0.1.6, parseuri@0.0.2, engine.io-client@1.5.1)
同樣很順利地完成。npm 就像 ROR 的 Gem 一樣,十分方便好用。

沒有留言: