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

util.scaffold

v0.0.38

Published

A library to simplify SSH interactions with a remote server. It can be used to run commands, change config, create files, etc.

Downloads

107

Readme

util.scaffold

A library to simplify SSH interactions with a remote server. It can be used to run commands, change config, create files, etc.

build analysis code style: prettier testing NPM

This module contains functions for simplifying SSH interactions with the remote production server. It can be used to run commands, change config, create files, etc.

Each of the calls to run, sudo, etc, are sent to a command list queue. Once the commands are queued up, then the go function is called to process the commands in order. This class is used to group together dependent functions. Each grouping of commands should be a separate instantiation of the Scaffold class. e.g.

let scaffold = new Scaffold(config.ssh);

scaffold
    .run('uname -a')
    .sudo('env | sort')
    .go();

Note that coverage is difficult with this module. It requires a host that can be used connected to via SSH and that the user has full control over that host.

Installation

This module uses yarn to manage dependencies and run scripts for development.

To install as an application dependency:

$ yarn add util.scaffold

To build the app and run all tests:

$ yarn run all

Usages

To connect to a remote server and execute a set of commands:

const Scaffold = require('util.scaffold').Scaffold;

let config = {
    "hostname": "example.com",
    "host": "192.168.1.42",
    "port": 22,
    "username": "centos",
    "privateKeyFile": "~/.ssh/id_rsa",
    "publicKeyFile": "~/.ssh/id_rsa.pub"
};

new Scaffold(config)
    .run('uname -a')
    .sudo('env | sort')
    .mkdir('/var/log/myapp', {mode: '700', owner: 'root', group: 'docker'})
    .put('/tmp/file1.txt', '/tmp/file2.txt')
    .go((err) => {
        if (err) {
            console.error(err);
            return;
        }

        console.log('Done.');
    })

An instance of the Scaffold class is created. Methods can be chained to this instance to queue commands. The first command above runs the uname command on the remote server. It runs it as the centos user. The second command dumps a sorted list of environment variables using sudo. This assumes that the SSH user centos has sudo permissions (or this command will fail). The third chained command creates a directory named /var/log/myapp and sets the permissions/ownership of the directory. The fourth command takes a file on the local machine and moves it to the remote machine. It works with text files only. All four of these commands are added to a queue. Execution starts when the go command is called. It processes each command in order. When it finishes a callback is executed. The callback uses the "error first callback" convention in node.

API

The module is composed of one class named Scaffold. It has the following public functions:

  • copy - copies a file on the remote machine from one location to another on the remote machine.
  • go - starts the processing of the command queue.
  • mkdir - creates a directory on the remote host.
  • put - takes a file from the local host and puts it on the remote host.
  • run - runs a command on the remote host.
  • sudo - runs a command on the remote host using sudo.