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

hussh

v0.0.3

Published

SSH2 wrapper

Downloads

1

Readme

HuSSH

HuSSH is a simple wrapper for ssh2 with only a few simple features:

  • Connects when you give it work to do
  • Always passes ENV vars (by prepending them to commands)
  • Simplified interface for uploading, downloading
  • Simplified methods for command execution:
    • buffering stdout/stderr
    • just waiting for exit code
  • Optionally logs activity to a local file
  • Tell the dog

If you need anything more complex than file upload/download and command execution, use ssh2 directly. If you don't need/want very simplified commands, use ssh2.

var hussh = require("hussh")
var client = hussh({
  host: "example.com",
  username: "foo",
  privateKey: require("fs").readFileSync("./my-secret.key")
}, {encoding: "utf-8"});

// upload a string to a remote file
client.uploadString("text for my file", "remote-file.txt", function(err){
  if ( ! err ) {
    // file contents uploaded
  }
});

// execute a command and save all buffered output
client.execBuffer("env", {MYENVVAR: "myenv-value"}, function(err, result){
  if ( ! err ) {
    // command exit status is 0, access result.stdout and result.stderr here
  }
  else {
    // command had non-zero exit status... see what happened
    console.error(err.message)
  }
});

Instantiation

var client = hussh(sshOptions, moreOptions);
  • sshOptions: these are passed directly to ssh2.connect
    • username: if not set, will be set according to precedence:
      • moreOptions.username
      • process.env.USER
      • "root"
    • host: if not set, will be set according to precedence:
      • moreOptions.hostname
      • moreOptions.host
      • "localhost"
    • All other options (such as privateKey) check ssh2 docs.
  • moreOptions: these only affect hussh, not ssh2 (except as noted above)
    • env: ENV vars to include for all further commands
    • encoding: sets encoding for local log file, uploadString() method
    • logStream: WriteableStream for logging hussh instance activity
    • logFile: (only when logStream absent) file to log activity

Command Execution

client.exec(command, env, callback);
client.execBuffer(command, env, callback);
client.execStatus(command, env, callback);
  • command: (String) command, including arguments
  • env: (Object) if given, the environment variables will be set (prepended to command in KEY=value style)
  • callback: (Function) called with the following:
    • err: null if OK, Error object otherwise
    • result: type depends the method used:
      • exec: ssh2 Channel (just like calling ssh2.Client.exec)
      • execBuffer: object with stdout and stderr Strings or Buffers
      • execStatus: result is omitted (undefined)

File Upload/Download

client.uploadString(stringData, remoteFile, callback);
client.upload(localFile, remoteFile, callback);
client.download(remoteFile, localFile, callback);

These are all just shortcuts which create an SFTP session, handle streams, and call the callback (receives Error on failure).