connect clickhouse server over ssh tunnel.
sshConfigshould be an object according to thessh2package. see options.chConfigshould be an object according to theclickhousepackage. see options- Returns a Object, containing a
clientfrom theclickhousepackage andclosefunction.
Don't forget to close() the tunnel connection when you're done with clickhouse.
npm install clickhouse-ssh
(async () => {
const { client, close } = await require('clickhouse-ssh').connect({
host: '127.0.0.1',
port: 22,
username: 'user',
password: 'pass',
}, {
host: '127.0.0.1',
port: 8123,
auth: 'user:pass'
});
try {
const result = await client.querying('select 1 as c');
console.log(result);
} catch (e) {
console.log(e);
} finally {
close();
}
})();