kunklejr/node-db-meta — pull request #7 by jeromew (2014-06-27 14:16:36+00:00)
Title: Do not require pg if it cannot be resolved

Hello,

I am trying to use db-meta for postgres, but only via exports.connectToExistingConnection since the pg connection comes from a pool.

In my setup, `pg` cannot be resolved so the `var pg=require('pg')`line breaks everything.

This PR uses require.resolve() in a try/catch block to discover if `pg` module can be resolved or not.

The require is only done if `pg` can be resolved.

Note that I used the 2 steps resolve/require in order to not put the require inside the try/catch block since code inside try/catch blocks cannot be optimized by V8.

Hope this helps.

ps: I am sorry I did not write a test for this and understand that this is not a perfect PR according to your standards. My setup uses node v0.11.9 and I could not even do `npm install` after cloning db-meta.