New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fork-require

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fork-require

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

latest
Source
npmnpm
Version
1.0.9
Version published
Weekly downloads
18
-10%
Maintainers
1
Weekly downloads
 
Created
Source

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.

      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 mallox@pyxzl.net or file an issue directly on Github. Thanks!

Keywords

fork

FAQs

Package last updated on 02 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts