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

promised-ssh

v0.6.2

Published

Promise wrapped ssh2

Downloads

8

Readme

promised-ssh

Promise wrapped ssh2

Install

npm install --save promised-ssh

Usage

.connect(options)

Takes a object with options similar to ssh2. This object is passed along to ssh2 connect. It returns a promise of an Connection.

.connectMock(options)

Returns a MockConnection which behaves similarly to Connection except it never tries to connect anywhere and the outcome of commands and the mocked connection is determined by mock-options which can be set with .setMockOptions.

.setMockOptions(options)

Sets the options used to determine the outcome of MockConnection.connect and MockConnection.exec. It takes an object with options. The possible options are:

  • failConnect (boolean) - Tells whether MockConnection.connect should fail or not. Default is false. If this is true it will throw an ConnectionError which is exposed under errors.
  • commands (object) - An object with information about return code, stdout and stderr that a command should give. All three options is optional and have the following defaults: code=0, stdout='', stderr=''. The default for the option is {}
  • throwIfMockNotDefined (boolean) - Throw an error if exec is called on a command that doesn't have a mock output defined

Example

ssh.setMockOptions({
  commands: {
    'cd project && make': {
      stdout: 'make: Nothing to be done for `all`.'
    }
  }
})

.setOfflineMode(true)

Will prevent any real connections from being made, causing an error to be throwin instead. Useful when in test mode to make sure tests don't trigger connections to remote servers.

Connection

Connection.connect()

Returns a promise that resolves a Connection-object when ssh2 opens a connection. this.options is used as connect options in ssh2.

Connection.exec(list_of_commands)

Takes a list of commands to run on the current connection. After the commands have been runned the connection will be closed. It returns a promise of an array: [stdout, stderr].

Example

var ssh = require('promised-ssh');

ssh
  .connect({
    host: 'localhost',
    username: 'rolf',
    privateKey: '...'
  })
  .then(function(connection) {
    return connection.exec(['ls -al']);
  })
  .spread(function(stdout, stderr) {
    console.log('Returned with return code ' + return_code);
    if (stdout) console.log('STDOUT: ' + stdout);
    if (stderr) console.log('STDERR: ' + stderr);
  })
  .catch(function(error) {
    // error is here an instance of ssh.errors.CommandExecutionError
    // it contains information about exit code, stdout and stderr
    throw error;
  });