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

child-io

v0.4.3

Published

Create child process for executing dangerous(user-made) function.

Downloads

5

Readme

child-io

Rank
Version Build status

Create child process for safe execution of dangerous(e.g. user-made) function.

Install

To install the most recent release from npm, run:

	npm i child-io

Usage

	const io = require('child-io').IO([forkArgs, [options]]);
	io.exec(func | file, [execOpts]);
  • forkArgs <Array>
    process arguments used when child_process is .fork() ed.

  • options <Object>

    • wkdir: [<String>]
    • modules: [<Array>]
  • func <Function>|<String> | file <String>
    executing original function.
    eval() or require() should be success to extract item.

  • execOpts <Object>

    • timeout: [<Number>] (alias: limit, Default = 5_000ms) max time to finish executing (millisecond).

    • reuse : [<Function>|<Any>]
      Judge whether kill or not after execute the process.

    • replace: [<Object>] (Default = { }) String replacement for using variable in executing function.

    • escape : [<Function>|] (Default = true) Escape the replaced string not to fail eval(). when truely value is given, the function below is used.

      function defaultEscaper(s) { return s.replace(/['"]/g, '\"').replace(/[\r\n]/g, '\n'); }

    • args : [<Array>] (Default = [ ])
      given arguments when the function is executed.
      the data send function "sender" will be put to.

  • Event

    • data
    • end
    • timeout
    • error

simple return

	const io = require('child-io').IO();
	io.on('data', function(ret){
	  console.log('Result: ' + ret); // "Result: true"
	}).on('end', function(msec){
	  console.log('Killed child_process(sync). Execute time is: ' + msec + ' ms');
	}).exec(function(){ return true; });

use asynchronous callback

	const io = require('child-io').IO();
	io.on('data', function(ret){
	  console.log('Result: ' + ret); // "Result: false"
	}).on('end', function(msec){
	  console.log('Killed child_process(async). Execute time is: ' + msec + ' ms');
	}).exec(function(sender){ process.nextTick(function(){ sender(false) }); });

See child-io_test.js for a sample to recognize more contract usage. You could run the code by npm run sample.

Note

FakeChild class is used automatically when v8debug is tied up. In that case, message Currently, typeof v8debug is NOT undefined. is shown.

Change Log

  • 2024/1/26

    • 0.4.3 release
    • add option "wkdir" and "modules"
  • 2024/1/26

    • 0.4.1 release
    • emit "error" event on timeout
    • new option: reuse
  • 2014/6/26

    • 0.3.3 release
    • option "escape" is included and the default is true
  • 2013/5/24

    • 0.3.1 release
    • add FakeChild class for --debug environment
  • 2013/4/16

    • 0.2.0 release
    • add option key 'args'
    • add "timeout" event
    • add wrap function for asynchronous use
    • add more explanation for each arguments,
    • add list of Event
  • 2013/4/15

    • 0.1.3 release
    • npm release