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 🙏

© 2025 – Pkg Stats / Ryan Hefner

forkme

v2.0.1

Published

Spawn a process without a module

Readme

forkme

Travis branch

Spawn a process without a module

(does NOT write any temporary files)

Installation

yarn add forkme

Usage

let forkme = require('forkme');

Basic Use

var child = forkme(function () {
    console.log("running in a child process!");
});

Context

A fake copy of the calling module is created in the child process, so as much as possible the closure should behave as if it's still in the module that called forkme().

One possible way in which the calling module and the closure module might differ, is that the closure module will be the main module of the child process.

forkme(function () {
	console.log(require.main === module); // true
});

require module.require

Modules required from the closure should resolve the same way they would if they had been required in the calling module.

Given:

  • Calling module "/path/to/calling-module.js"
  • Other module "/path/to/node_modules/foo/index.js"
  • Other module "/path/to/bar.js"

Then:

forkme(function () {
	console.log(require.resolve('foo')); // "/path/to/node_modules/foo/index.js"
	console.log(require.resolve('./bar')); // "/path/to/bar.js"
});

__filename __dirname module.filename

These variables have the same values in the closure as they did in the calling module.

module.id

This will be "." because the closure is the main module of the child process.

Arguments

An optional array of values can be passed as the first argument. The values will be passed to the closure when it's called in the child process.

forkme(['foo', 'bar'], function(a, b) {
    console.log(a + " " + b); // "foo bar"
});

All values in the arguments array must be JSON serializable.

Options

Environment variables, working directory, input and output streams, etc., can be modified by passing an options object. The options are passed directly to child_process.fork().

var child = forkme({
    cwd: "/some/path",
    env: { foo: 'bar' },
    silent: true // Pipe stdin, stdout, and stderr to parent process.
}, function () {
    console.log(process.cwd() + ", " + process.env.foo);
});

child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
	process.stdout.write(data); // "/some/path, bar";
});

Return

If the closure returns a defined value, an IPC message will be sent back to the parent process with the returned value. The return value should be JSON serializable.

var child = forkme(function () {
	return 'foo';
});

child.on('message', function (message) {
	console.log(message); // "foo"
});

API

forkme(closure) forkme(args, closure) forkme(options, closure) forkme(args, options, closure)

  • args Array (optional)
  • options Object (optional)
  • closure Function
  • returns ChildProcess

Spawns a child process which calls the closure, passing it all values in the args array.

The options argument is passed directly to child_process.fork(). See the documentation for child_process.fork() for more information.

A standard Node.js ChildProcess instance is returned.