https://github.com/craigwardman/subspawn
An npm library for spawning (and killing) synchronous and asynchronous sub processes from node.
https://github.com/craigwardman/subspawn
child-process node process
Last synced: over 1 year ago
JSON representation
An npm library for spawning (and killing) synchronous and asynchronous sub processes from node.
- Host: GitHub
- URL: https://github.com/craigwardman/subspawn
- Owner: craigwardman
- License: mit
- Created: 2022-12-19T10:22:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-02T09:36:34.000Z (over 2 years ago)
- Last Synced: 2025-02-28T21:41:03.425Z (over 1 year ago)
- Topics: child-process, node, process
- Language: TypeScript
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# subspawn
An npm library for spawning (and killing) synchronous and asynchronous sub processes from node.
This package is a wrapper around Node's `child_process` library, which offers the ability to create child processes but isn't as easy
to get working as you might hope.
The idea behind this code is to provide:
1) A cross platform way of creating child processes that will share the stdout of the parent (including 'npm' scripts)
2) Synchronous and asynchronous methods of running the sub processes
3) A cross plaform way of killing the child processes, including any descendants of those child processes
The original use-case for this module was for use in a complex npm build script, whereby writing the build sequence as TypeScript made
more sense than daisy chaining lots of "npm" commands together. You can read more about this too on my blog: http://www.craigwardman.com/Blogging/BlogEntry/writing-an-npm-startup-script-in-typescript-to-support-complex-scenarios
# usage
Install the package into your application of choice the usual way (`npm i subspawn`)
Import the module into your JavaScript or TypeScript node file (`import { subProcess, subProcessSync } from 'subspawn'`)
Use the appropriate function to run a child process,
```
subProcessSync(, )
subProcess(, , )
```
e.g.
Synchronous:
`subProcessSync('npm run tsc', true)`
This will block execution until the command completes, so no "child process" needs to be cleaned up at the end.
Asynchronous:
`subProcess('build', 'npm run start-bg-service', true)`
This will not block execution, and the "child process" will be killed when the parent process exits (or earlier if you call `killSubProcesses('build')`)