小さい頃はエラ呼吸

いつのまにやら肺で呼吸をしています。


node.js + PostgreSQLの連携ライブラリnode_postgresをビルドする

はじめに

Ubuntu 10.10の環境でnode.js + PostgreSQLの連携ライブラリnode_postgresをビルドしてみました。

node_postgresをビルドする

gitのインストール

sudo apt-get install git

git cloneコマンドでnode_postgresを取得します。

git clone https://github.com/ry/node_postgres.git

ディレクトリを移動します。

cd node_postgres/

node-waf configure buildでビルドします。

node-waf configure build
(中略)
>Checking for program pg_config           : not found 
>/home/replication/node_postgres/wscript:16: error: The program ['pg_config'] is required

pg_configが見つからないと言われてしまいました。以下のサイトによると、pg_configはlibpq-devに含まれているようです。

/usr/bin/pg_config is in the package libpq-dev.
[ubuntu] Can't find pg_config? PostgreSQL problem - Ubuntu Forums はてなブックマーク - [ubuntu] Can't find pg_config? PostgreSQL problem - Ubuntu Forums

libpq-devをインストールします。

sudo apt-get install libpq-dev

もう一度、ビルドを実行します。

node-waf configure build
>Checking for program g++ or c++          : /usr/bin/g++ 
>Checking for program cpp                 : /usr/bin/cpp 
>Checking for program ar                  : /usr/bin/ar 
>Checking for program ranlib              : /usr/bin/ranlib 
>Checking for g++                         : ok  
>Checking for node path                   : not found 
>Checking for node prefix                 : ok /usr/local 
>Checking for program pg_config           : /usr/bin/pg_config 
>'configure' finished successfully (1.017s)
>Waf: Entering directory `/home/replication/node_postgres/build'
>Waf: Leaving directory `/home/replication/node_postgres/build'
>'build' finished successfully (0.096s)

今度はうまくいきました。

続いて、npmコマンドでインストールを実施します。

sudo npm install .
>npm info build Success: postgres@0.0.1
>npm ok

ビルドとインストールまではできたのですが、同胞されているtest.jsを動かすとやっぱりエラーになりました。これについては次回までの宿題にしたいと思います。

node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
8 Mar 02:03:19 - [ERROR] Error
Error: connection pointer is NULL

at Object.createConnection (/home/replication/node_postgres/postgres.js:53:5)
at Object. (/home/replication/node_postgres/test.js:9:18)
at Module._compile (module.js:373:26)
at Object..js (module.js:379:10)
at Module.load (module.js:305:31)
at Function._load (module.js:271:10)
at Array. (module.js:392:10)
at EventEmitter._tickCallback (node.js:108:26)