Skip to content

narekhovhannisyan/node-ssh-extra

Repository files navigation

node-ssh-extra

Build Status

Node SSH wrapper which helps to reuse existing connections.

This module keeps all connections in cache for further usage.

Under the hood cache eventually checks if connectionExpire time is passed. If it is, then it removes connection from cache.

Usage

For separate servers.

const NodeSSHExtra = require('node-ssh-extra')

const sshInstance = NodeSSHExtra({
  privateKey, // Private key path for ssh connection.
  host, // name for ssh connection.
  passphrase, // Passphrase for ssh connection.
  username, // User name for ssh connection.
  connectionExpire, // Milliseconds to expire ssh connections.
  domainOrIP // Domain or IP address to connect.
})

sshInstance()
  .then((connection) => {
    // Do whatever you need to do here.
  })

// And after if you need to do some other thing on the same server, just call `sshInstance` the same way.
// It will re-use the old opened connection if it's not expired, otherwise will create new connection.

Contribution

For contributing please see contribution rules