foreground-child
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
cross-spawn | 7.0.3 | 7.3 kB | MIT | prod | |
signal-exit | 4.1.0 | 13.06 kB | ISC | prod |
Foreground-child is a JavaScript module that allows you to run a child process as if it were the main or foreground process. It hands over console input and output to the child process and makes the parent process exit when the child does. Its primary applications include wrapping child processes for test coverage, as well as any other situation where it's useful to make one program execute another as the main program.
Usage of foreground-child is straightforward. First, you need to import the foregroundChild
function from the foreground-child
module. You then call foregroundChild
, passing the command name and any arguments as parameters. The command runs as if it were the main process, and the parent process will exit when the child does.
Here is a basic usage example:
import { foregroundChild } from 'foreground-child'
const child = foregroundChild('cat', [__filename])
You can also provide custom spawn options to control how the child process is spawned:
const child = foregroundChild(`cat ${__filename}`, { shell: true })
and optionally a callback function to be executed before the process exits:
const child = foregroundChild('cat', [__filename], spawnOptions, () => {
doSomeActions()
})
or a promise for asynchronous actions:
const child = foregroundChild('cat', [__filename], async () => {
await doSomeAsyncActions()
})
The documentation for the foreground-child module can be found on the README page in its GitHub repository. The URL for the repository is git+https://github.com/tapjs/foreground-child.git. The README provides clear instructions for using the module and provides several useful examples. Visit the README page to consult the full documentation and get a comprehensive overview of the module.