Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const tunnel = require('tunnel-ssh');
- import knexLib = require('knex');
- async function main() {
- const sshUserName = 'SSH_USER_NAME';
- const sshPassword = 'SSH_PASSWORD';
- let sshConfig = {
- host: 'SSH_HOST_ADDRESS',
- port: SSH_PORT,
- username: sshUserName,
- password: sshPassword,
- keepaliveInterval: 60000,
- keepAlive: true,
- dstHost: 'TUNNEL_DEST_HOST_ADDRESS',
- dstPort: TUNNEL_DEST_PORT,
- localHost: 'localhost',
- localPort: 45432
- };
- const tnl = tunnel(sshConfig, async (err: any, server: any) => {
- if (err) {
- throw err;
- }
- let knex = knexLib({
- client: 'postgresql',
- connection: {
- database: 'DATABASE_NAME',
- port: 45432,
- user: 'DATABASE_USER',
- password: 'DATABASE_PASSWORD'
- }
- });
- const rows = await knex.select().from(TABLE_NAME);
- console.log(rows);
- await knex.destroy();
- tnl.close();
- });
- }
- main();
Add Comment
Please, Sign In to add comment