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

cp-remote

v1.0.2

Published

Remote child_process runner with message support

Downloads

43

Readme

cp-remote   Build Status Coverage Status NPM version

Node.js child_process done remotely, IPC channel intact!

Example:

var cp_remote = require('cp-remote');
var assert = require('assert');
var remote = cp_remote.run('host', '/path/on/host/to/sub.js', 'foo', { answer: 42 });
remote.on('message', function (msg)
{
    assert.deepEqual(msg, { foo: 'bar' });
});
remote.send({ hello: 'world' });

You might implement the remote script, sub.js, like this:

var assert = require('assert');
assert.equal(process.argv[2], 'foo')
assert.deepEqual(process.argv[3], { answer: 42 });
process.on('message', function (msg)
{
    assert.deepEqual(msg, { hello: 'world' });
    process.disconnect();
});
process.send({ foo: 'bar' });

The API is described here.

Pre-requisites

Client:

  • SSH client (e.g. OpenSSH), configured for password-less logon to the remote host (e.g. using a private key).
  • Node.js (of course)
  • Bash
  • socat

Remote host:

  • SSH server (e.g. OpenSSH)
  • Node.js (node command should be in the remote PATH of SSH sessions)
  • Python (it provides access to socketpair, Node does not)
  • socat

Installation

npm install cp-remote

Limitation

You can't pass handles to a remote child process like you can with local child processes.

How it works

How it works

  • cp-remote calls child_process.spawn to run a Bash script, cp-remote.sh. The IPC channel will be on $NODE_CHANNEL_FD.
  • cp-remote.sh runs socat, telling it to relay data between $NODE_CHANNEL_FD and an SSH connection to the remote host.
  • The SSH connection is told to start cp-remote.py on the remote host.
  • cp-remote.py calls socket.socketpair to create a pair of connected file descriptors (Unix domain sockets).
  • cp-remote.py starts socat, telling it to relay data between standard input (i.e. the SSH connection) and one of the connected file descriptors.
  • cp-remote.py sets NODE_CHANNEL_FD to the other connected file descriptor and starts node, telling it to run the module you specified.

Licence

MIT

Test

To test creating and communicating with remote child processes:

grunt test --remote=<host1> --remote=<host2> ...

You can specify as many remote hosts as you like. The test will try to create a remote child process on each host and then communicate with each one.

It assumes the cp-remote module is installed at the same path on each host.

Lint

grunt lint

Code Coverage

grunt coverage --remote=<host1> --remote=<host2> ...

c8 results are available here.

Coveralls page is here.

API

Source: index.js

run(host, module_path)

Run a Node.js module on a remote host and return a child_process.ChildProcess object for communication with it.

Parameters:

  • {String} host The name (or IP address) of the remote host to run the module on.
  • {String} module_path The path to the module on the remote host. Any arguments following module_path will be made available to the module in its process.argv (starting at the third element).

Return:

{child_process.ChildProcess} The ChildProcess object for the remote process. You can do the same things with this object as a local ChildProcess, except send it handles (i.e. the optional sendHandle parameter to child.send isn't supported).

Go: TOC

—generated by apidox