Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. var Clientssh = require('ssh2').Client;
  2. var conn = new Clientssh();
  3. conn.on('ready', function() {
  4. console.log('Client :: ready');
  5. conn.forwardOut(
  6. '127.0.0.1',
  7. 5434,
  8. 'localhost',
  9. 5432,
  10. function(err, stream) {
  11. if (err) throw err;
  12. let conf = {
  13. host: 'localhost',
  14. port: 5434,
  15. user: 'test',
  16. database: 'test',
  17. password: 'test'
  18. }
  19. let remoteConnection = new Client(conf);
  20. remoteConnection.connect(function(err) {
  21. if (err) {
  22. console.log(err);
  23. console.log("Unable to connect to postgre");
  24. res.send(err);
  25. } else {
  26. remoteConnection.query('SELECT * FROM test', function(err, testResult) {
  27. remoteConnection.end();
  28. if (err) {
  29. console.log("Unable to fetch data");
  30. res.send(err);
  31. } else {
  32. console.log("Succcess");
  33. res.send(testResult);
  34. }
  35. });
  36. }
  37. });
  38. });
  39. }).connect({
  40. host: 'hostaddress',
  41. port: 'hostport',
  42. username: 'hostusername',
  43. privateKey: require('fs').readFileSync('path/for/key')
  44. });
  45.  
  46. Client :: ready
  47. Error: Connection terminated unexpectedly
  48. at Connection.con.once (/node-postgres/node_modules/pg/lib/client.js:235:9)
  49. at Object.onceWrapper (events.js:286:20)
  50. at Connection.emit (events.js:198:13)
  51. at Channel.<anonymous> (/node-postgres/node_modules/pg/lib/connection.js:131:10)
  52. at Channel.emit (events.js:203:15)
  53. at endReadableNT (_stream_readable.js:1129:12)
  54. at process._tickCallback (internal/process/next_tick.js:63:19)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement