dracoblue.net

How to use postgres with nodeJS

With NodeJS (built on V8) it's pretty simple to access libraries written in C/C++.

Since NodeJS is 100% non-blocking I/O you'll need to tell your libraries to do the same. Even though libmysql is not yet capable of doing that, you may use postgres for this.

Ryan's node_postgres is a binary binding.

Compiling is easy as usual:

$ node-waf configure build
This may not work if a bug in node-waf is still present. So you get the error: Version mismatch: waf 1.5.9 <> wafadmin 1.5.10. To fix that edit /usr/local/bin/node-waf and change 1.5.9 to 1.5.10.

If you receive the error: The program pk_config could not be found, you'll need to install postgres dev libraries package first. On debian/ubuntu you do that the following way:

$ sudo apt-get install libpq-dev

It may fail to build then with the message: "Build failed", "cxx binding.cc -> binding_1.o". I am currently running into the same issue and will post an update as soon as I got this fixed.

There is also an pure Javascript implementation of the Postgres API available at

postgres-js.

In javascript, node.js by
@ 23 Dec 2009, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About