var pg = require('pg'), | |
url = require('url'), | |
SocksConnection = require('socksjs'); | |
var db = url.parse(process.env.REDSHIFT_CONN_STRING), | |
dbAuth = db.auth, | |
dbUsername = dbAuth.split(':')[0], | |
dbPassword = dbAuth.split(':')[1], | |
dbName = db.pathname.replace('/', ''); | |
var proxy = url.parse(process.env.QUOTAGUARDSTATIC_URL), | |
auth = proxy.auth, | |
username = auth.split(':')[0], | |
pass = auth.split(':')[1]; | |
var sock_options = { | |
host: proxy.hostname, | |
port: 1080, | |
user: username, | |
pass: pass | |
}; | |
var remote_options = { | |
host: db.hostname, | |
port: db.port | |
}; | |
var sockConn = new SocksConnection(remote_options, sock_options); | |
var config = { | |
user: dbUsername, | |
database: dbName, | |
password: dbPassword, | |
stream: sockConn | |
}; | |
var client = new pg.Client(config); | |
// connect to our database | |
client.connect(function (err) { | |
if (err) throw err; | |
// execute a query on our database | |
client.query('SELECT $1::text as name', ['john doe'], function (err, result) { | |
if (err) throw err; | |
// just print the result to the console | |
console.log(result.rows[0]); // outputs: { name: 'apiary' } | |
// disconnect the client | |
client.end(function (err) { | |
if (err) throw err; | |
}); | |
}); | |
}); |
This comment has been minimized.
This comment has been minimized.
Hi, can you pls explain how to form process.env.REDSHIFT_CONN_STRING for node js app |
This comment has been minimized.
This comment has been minimized.
As you see using https://nodejs.org/docs/latest/api/url.html for example |
This comment has been minimized.
This comment has been minimized.
https://github.com/brianc/node-postgres/blob/master/lib/connection.js#L22 |
This comment has been minimized.
This comment has been minimized.
Hi, Thanks for reply I am connecting to aws redshift db and I use Env variable like PGSSLMODE=require and that solved the connectivity issue. By the way I am using "pg" NPM package for redshift in my Node app and my co-workers think that the client machine must have JAVA runtime or some JDBC/ODBC driver on the computer where Node app is running. Pleases let me know if that is right. |
This comment has been minimized.
This comment has been minimized.
Not sure about that. I don't use java for long time. node-pg using C++ bindings. |
This comment has been minimized.
This comment has been minimized.
not working for me
My packages
|
This comment has been minimized.
This comment has been minimized.
Hi, I am facing the same issue. Does someone has an answer for this? thank you. TypeError: this.stream.setNoDelay is not a function |
This comment has been minimized.
This comment has been minimized.
Example with with |
This comment has been minimized.
I'm curious, where that stream option comes from?