Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Clientssh = require('ssh2').Client;
- var conn = new Clientssh();
- conn.on('ready', function() {
- console.log('Client :: ready');
- conn.forwardOut(
- '127.0.0.1',
- 5434,
- 'localhost',
- 5432,
- function(err, stream) {
- if (err) throw err;
- let conf = {
- host: 'localhost',
- port: 5434,
- user: 'test',
- database: 'test',
- password: 'test'
- }
- let remoteConnection = new Client(conf);
- remoteConnection.connect(function(err) {
- if (err) {
- console.log(err);
- console.log("Unable to connect to postgre");
- res.send(err);
- } else {
- remoteConnection.query('SELECT * FROM test', function(err, testResult) {
- remoteConnection.end();
- if (err) {
- console.log("Unable to fetch data");
- res.send(err);
- } else {
- console.log("Succcess");
- res.send(testResult);
- }
- });
- }
- });
- });
- }).connect({
- host: 'hostaddress',
- port: 'hostport',
- username: 'hostusername',
- privateKey: require('fs').readFileSync('path/for/key')
- });
- Client :: ready
- Error: Connection terminated unexpectedly
- at Connection.con.once (/node-postgres/node_modules/pg/lib/client.js:235:9)
- at Object.onceWrapper (events.js:286:20)
- at Connection.emit (events.js:198:13)
- at Channel.<anonymous> (/node-postgres/node_modules/pg/lib/connection.js:131:10)
- at Channel.emit (events.js:203:15)
- at endReadableNT (_stream_readable.js:1129:12)
- at process._tickCallback (internal/process/next_tick.js:63:19)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement