npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ssh2-connect

v3.4.2

Published

Callback-based api behind ssh2 to open an SSH connection

Downloads

3,998

Readme

Build Status

Node.js ssh2-connect

The Node.js ssh2-connect package extends the ssh2 module to provide a simplified callback-back approach to initiate a new SSH connection.

Usage

The connect function return a promise. Its signature is await connect(options)

It also accept an optional callback function. In such case, its signature is connect(options, callback).

This package simplifies the creation of an SSH connection. For example, the original ssh2 code...

const ssh2 = require('ssh2')
const connection = new ssh2()
connection.on('error', function(err){
  // Handle the connection error
  connection.end()
})
connection.on('ready', function(){
  // Work with the connection
  connection.end()
})
connection.connect({
  host: 'localhost',
  user: 'milou',
  password: 'wafwaf'
})

...is simplified to:

const connect = require('ssh2-connect')
(async () => {
  try{
    const ssh = await connect({
      host: 'localhost',
      username: 'david',
      private_key_path: '~/.ssh/id_rsa'
    })
    // Work with the connection
    ssh.end()
  }catch (err){
    // Handle the connection error
  }
})()

Options

Options are inherited from the ssh2 Connection.prototype.connect function with a few additions:

  • username
    The username used to initiate the connection, default to the current environment user.
  • privateKeyPath
    Path of the file containing the private key, true to enable auto-discovery or false to disable auto-discovery, default to true.
  • retry Attempt to reconnect multiple times, default to 1.
  • wait Time to wait in milliseconds between each retry, default to 2000.

Note, the "privateKeyPath" option is provided as a conveniency to read the private key and fill the "privateKey" property.

Additionally, all options may be provided in camalize (the default in ssh2) or underscore form. For example, both "privateKey" and "private_key" would be interprated the same.

Installation

This is OSS and licensed under the new BSD license.

npm install ssh2-connect

Examples

The example is using both the "ssh2-connect" and "ssh2-fs" modules.

const connect = require('ssh2-connect');
const fs = require('ssh2-fs');
// Open the connection
connect({host: 'localhost'}, function(err, ssh){
  // Create a directory
  fs.mkdir(ssh, '/tmp/a_dir', (err, stdout, stderr){
    console.log(stdout);
  });
});

Compare this to the more verbose alternative using the original ssh2 module.

ssh2 = require('ssh2');
fs = require('ssh2-fs');
connection = new ssh2();
connection.on('error', function(err){
  connection.end()
});
connection.on('ready', function(){
  fs.mkdir(connection, '/tmp/a_dir', (err, stdout, stderr){
    console.log(stdout);
  });
});
connection.connect({host: 'localhost'});

Development

Tests are executed with mocha. To install it, simple run npm install, it will install mocha and its dependencies in your project "node_modules" directory.

To run the tests:

npm test

To generate the JavaScript files:

npm run build

The test suite is run online with Travis against several Node.js version.

To version and publish:

npm run release
npm publish

Contributors

This package is developed by Adaltas.