首先我们使用 Git 来获取实例源码
git clone https://github.com/indexzero/nodejs-intro.git
创建 CouchDB 数据库
在开始教程之前我们需要创建一个 CouchDB 数据库,先确保 CouchDB 已经启动,然后使用如下命令创建数据库:
$ curl -X PUT http://127.0.0.1:5984/pinpoint-dev10
{“ok”:true}
你可以在浏览器中访问 http://127.0.0.1:5984/_utils 就可以看到新创建的数据库。
这里还有一个非常棒的 CouchDB 的指南。
开始教程
node js 实例使用模块化的方式构建,lib 目录包含很多模块,而服务器脚本在 bin 目录下。
例如,我们要启动 CouchDB 教程,可以在 bin 目录下执行下面命令:
./server -t 02couchdb -s
其中 -t 参数允许你指定要执行的 lib 目录下的模块,-s 参数用以设置我们刚建立的 pinpoint-dev 数据库。
sys – util 变化
根据 Node.js 的版本不同,你可能会看到如下的错误或者是警告:
$ node -v
v0.7.7-pre
$ ./server -t 02couchdb -s
node.js:247
throw e; // process.nextTick error, or ‘error’ event on first tick
^
Error: The “sys” module is now called “util”.
at sys.js:1:69
at NativeModule.compile (node.js:572:5)
at Function.require (node.js:540:18)
at Function._load (module.js:297:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object. (/home/ubuntu/nodejs-intro/bin/server:3:11)
at Module._compile (module.js:444:26)
at Object..js (module.js:462:10)
at Module.load (module.js:351:32)
为了避免这个问题,你需要将所有调用 `require(“sys”)` 替换成 `require(“util”)`
Node v0.6.14 不会抛出错误信息,但会提示警告:
$ node -v
v0.6.14
$ ./server -t 02couchdb -s
The “sys” module is now called “util”. It should have a similar interface.
Pinpoint demo server listening for 02couchdb on http://127.0.0.1:8000
运行教程
当你运行某个教程时,会提示一些错误:
$ ./server 02couchdb
The “sys” module is now called “util”. It should have a similar interface.
node.js:201
throw e; // process.nextTick error, or ‘error’ event on first tick
^









