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

@usys/fork-require

v1.0.9-unb3

Published

Allows to "require" a file, while forking it into a child process.

Downloads

487

Readme

fork-require

Allows to "require" a file, while forking it into a child process.

npm version Build Status Coverage Status Dependency Status

About

This nifty little library makes spawning processes and interacting with them super easy. It will automatically fork any file you give it and proxy all method calls to the forked child process. All responses are returned via Promises and make it really easy to read with the async/await syntax.

Example

An example might make it easier to understand. This will fork a new module and allow you to call any method on it.

const fork = require('fork-require');

let otherModule = fork('./otherModule');

let response = await otherModule.doSomething('Hello');
// => will print "Hello World" in a separate process.

The file you want to fork-require would look like this:

/*** otherModule.js ***/

exports.doSomething = function(val) {
    console.log(val, 'World');
}

Installation

In your npm project directory run

npm i --save fork-require

API

There's only one method call available:

fork( file, [options] )

  • file
  • options
    • args <string[]> Allows you to set the arguments with which to spawn the process (Default: process.args)
    • env Allows you to set the environment properties with which to spawn the process (Default: process.env)
    • cwd Allows you to set the current working directory in which to spawn the process (Default: process.cwd())
    • execArgv <string[]> Allows you to set the executable (most likely node) arguments with which to spawn the process (Default: process.execArgv)
    • execPath Allows you to set the path to the executable with which to spawn the process (Default: process.execPath)
    • fixStack Allows you to see the original stack trace on errors instead of the adapted ones(Default: true)

Caveats

There is no support for properties on target modules, so if you're trying to access those that won't work. Also you need to handle the response via Promises. If you don't use await/then() you will not get results, so don't forget.

Additionally don't forget that you are invoking inter process communication here which is much slower than directly calling a method in a module (simple performance test shows a difference of factor 150-200). While the overhead might be negligible in most cases it will have an impact on high frequency interactions (overhead is about 0.00005ms per call for small payloads and will go up for larger payloads).

Tests

To run the tests you must install the development dependencies along with the production dependencies

npm install fork-require

After that you can just run npm test to see an output of all existing tests.

Bugs and Feature Requests

I try to find all the bugs and have tests to cover all cases, but since I'm working on this project alone, it's easy to miss something. Also I'm trying to think of new features to implement, but most of the time I add new features because someone asked me for it. So please report any bugs or feature request to [email protected] or file an issue directly on Github. Thanks!