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

@mh-cbon/remote-child_process

v1.0.7

Published

Spawn a child_process on a remote via a server almost like a normal child_process

Downloads

28

Readme

remote-child_process

Spawn a child_process on a remote via a server almost like a normal child_process.

Install

npm i @mh-cbon/remote-child_process --save

Usage

spawn

var Rcp         = require('@mh-cbon/remote-child_process')
var RcpServer   = Rcp.RcpServer;

var spawn       = Rcp.spawn;


var address = {host: '127.0.0.1', port: 8080};
var server = new RcpServer()

server.open(address, function () {
  var child = spawn('ls', ['-al'], {bridgeAddress: address, stdio: 'pipe'});

  child.stdout.pipe(process.stdout);
  child.stderr.pipe(process.stderr);
  // child.stdin.end('some data');

  child.on('error', function (err) {
    console.log(err); // it may also throw ECONNREFUSED
  })

  child.on('started', function (err) {
    console.log("pid=%s", child.pid);
  })

  child.on('exit', function (err) {
    console.log("exited");
  })
  child.on('close', function () {
    console.log("closed")
    server.close(force=!true);
  })
})

var tout = setTimeout(function () {
  throw 'no client connected yet'
}, 1500)

server.on('client_connected', function () {
  clearTimeout(tout)
})

exec

var Rcp         = require('@mh-cbon/remote-child_process')
var RcpServer   = Rcp.RcpServer;

var exec        = Rcp.exec;


var address = {host: '127.0.0.1', port: 8080};
var server = new RcpServer()

server.open(address, function () {
  var opts = {bridgeAddress: address};
  var child = exec('ls -al', opts, function (err, stdout, stderr) {
    console.log("exec end")
    console.log("error=%s", error);
    console.log("stdout=%s", stdout);
    console.log("stderr=%s", stderr);
  });

  child.on('error', function (err) {
    console.log(err); // it may also throw ECONNREFUSED
  })

  child.on('started', function (err) {
    console.log("pid=%s", child.pid);
  })

  child.on('exit', function (err) {
    console.log("exited");
  })
  child.on('close', function () {
    console.log("closed")
    server.close(force=!true);
  })
})

var tout = setTimeout(function () {
  throw 'no client connected yet'
}, 1500)

server.on('client_connected', function () {
  clearTimeout(tout)
})
  • pid and methods call are available after started event has emit
  • on network failure, it throw error on the child
  • the remote process is not running a TTY, so it may be a bit different
  • cwd is always forwarded and set appropriately

About the server

The server expose open and close method as expected.

Note that two alternative methods exists to close it.

via a socket

If you connect a socket on the server and send it a JSON packet

{
  "type": "close",
  "force": true
}

The close sequence will be invoked.

via a file

Alternatively it is possible to tell the server to watch for a specific file, containing a specific token to invoke its close sequence.


var server = ....

server.enableFileToQuit('file to watch', 'token to find in the file')

Why

It is used to spawn process on windows with elevated privileges, see here

Running the tests

To run the tests,

mocha

To run the tests against node.child_process api

LOCAL=true mocha