8

I'm trying to setup nodejs to access a postgres database. What I've done so far is the following (https://gist.github.com/579814):

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh

then

git clone git://github.com/isaacs/npm.git
make
make install

so far, so good. However, when I try to install the postgres driver

npm install pg

I get the following:

node-waf configure build || true

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 (0.066s)
Waf: Entering directory `/home/christian/node_modules/pg/build'
[1/2] cxx: src/binding.cc -> build/default/src/binding_1.o
../src/binding.cc:3:25: fatal error: node_events.h: No such file or directory
compilation terminated.
Waf: Leaving directory `/home/christian/node_modules/pg/build'
Build failed:  -> task failed (err #1): 
    {task: cxx binding.cc -> binding_1.o}

I've been looking around for setting the node path, although haven't found anything of help so far - probably also because I'm totally new to nodejs, so I'd be happy about any hint.

1
  • 2
    In newer versions of node.js, npm is included with node. You shouldn't need to do curl http://npmjs.org/install.sh | sh. Commented Apr 28, 2012 at 22:29

4 Answers 4

14

Now, you have NodeJS installed in your Ubuntu. You should set /etc/environment and load nodeJS path that can be executed by another users. For example:

NODE="/home/ubuntu/local/node"
NODE_PATH="/usr/local/lib/node_modules" 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$NODE/bin:$NODE/lib/node_modules"
#PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Sign up to request clarification or add additional context in comments.

1 Comment

Why that free hosting ad there :O
8

Do this in bash: echo 'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.bashrc

4 Comments

thanks, that actually helped to to fix the node path, although the error of not finding the node_events.h still remained.
look at /home/christian/node_modules/pg/build is node_events.h anywhere. And look at other modules. Does the have it?
couldn't locate node_events.h anywhere, so it seems to be missing for some reason. It seems to me that node_events.h was removed from nodejs (github.com/joyent/node/commits/master/src/node_events.h), so is it possible, that the pg-driver still requires it?
I think that it your problem. Nodejs and its db modules uses events machine for asynchronous calls. So that way pg need it too.
0

before things are fixed you must use node 0.5.1 (you can use gitk to revert the tree to this version)

Auteur: Ryan Dahl <[email protected]>  2011-07-19 10:46:38
Auteur du commit: Ryan Dahl <[email protected]>  2011-07-19 10:46:38
Parent: 0a3fc1d9c8becc32c63ae736ca2b3719a3d03c5b (Remove StatWatcher's dep on C++ EventEmitter)
Enfant:  061ce7b0ac370c8a5ae93d95ab7da171cbd488f0 (net_uv: Fix simple/test-http-expect-continue.js)
Branche: master, remotes/origin/master
Suit: v0.5.1
Précède: v0.5.2
Finally remove node::EventEmitter

Comments

0

I had the same problem. The issue was that I was specifying a old version of PG in my package.js After I removed the old version dependancy I was able to install PG without issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.