Skip to content

Commit

Permalink
Add comparison with Execa
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 7, 2024
1 parent e899294 commit b83beea
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,40 @@ This package fixes several cross-platform issues with [`node:child_process`](htt
- The [`PATHEXT`](https://wiki.tcl-lang.org/page/PATHEXT) environment variable.
- Windows-specific [newlines](https://en.wikipedia.org/wiki/Newline#Representation).

## Alternatives

`nano-spawn`'s main goal is to be small, yet useful. Nonetheless, depending on your use case, there are other ways to run subprocesses in Node.js.

### `node:child_process`

`nano-spawn` is built on top of the [`node:child_process`](https://nodejs.org/api/child_process.html) core module.

If you'd prefer avoiding adding any dependency, you may use `node:child_process` directly. However, you might miss the [features](#features) `nano-spawn` provides: [proper error handling](#subprocesserror), [full Windows support](#windows-support), [local binaries](#optionspreferlocal), [piping](#subprocesspipefile-arguments-options), [lines iteration](#subprocesssymbolasynciterator), [interleaved output](#resultoutput), [and more](#features).

```js
import {execFile} from 'node:child_process';
import {promisify} from 'node:util';

const pExecFile = promisify(execFile);

const result = await pExecFile('npm', ['run', 'build']);
```

### Execa

[Execa](https://github.com/sindresorhus/execa) is a similar package: it provides the same features, is also built on top of `node:child_process`, and is maintained by the [same people](#maintainers).

On one hand, it has a bigger size: [![Install size](https://packagephobia.com/badge?p=execa)](https://packagephobia.com/result?p=execa)

On the other hand, it provides a bunch of additional features: [scripts](https://github.com/sindresorhus/execa/blob/main/docs/scripts.md), [template string syntax](https://github.com/sindresorhus/execa/blob/main/docs/execution.md#template-string-syntax), [synchronous execution](https://github.com/sindresorhus/execa/blob/main/docs/execution.md#synchronous-execution), [file](https://github.com/sindresorhus/execa/blob/main/docs/output.md#file-output) or [binary input/output](https://github.com/sindresorhus/execa/blob/main/docs/binary.md), [advanced piping](https://github.com/sindresorhus/execa/blob/main/docs/pipe.md), [verbose mode](https://github.com/sindresorhus/execa/blob/main/docs/debugging.md#verbose-mode), [graceful](https://github.com/sindresorhus/execa/blob/main/docs/termination.md#graceful-termination) or [forceful termination](https://github.com/sindresorhus/execa/blob/main/docs/termination.md#forceful-termination), [IPC](https://github.com/sindresorhus/execa/blob/main/docs/ipc.md), [shebangs on Windows](https://github.com/sindresorhus/execa/blob/main/docs/windows.md), [and much more](https://github.com/sindresorhus/nano-spawn/issues/14). Also, it is [very widely used](https://github.com/sindresorhus/execa/network/dependents) and [battle-tested](https://github.com/sindresorhus/execa/graphs/contributors).

We recommend using Execa in most cases, unless your environment really requires using small packages (for example, in a library or in a serverless function).

## Maintainers

- [Sindre Sorhus](https://github.com/sindresorhus)
- [@ehmicky](https://github.com/ehmicky)

## Related

- [execa](https://github.com/sindresorhus/execa) - Process execution for humans
- [unicorn-magic](https://github.com/sindresorhus/unicorn-magic/blob/6614e1e82a19f41d7cc8f04df7c90a4dfe781741/node.d.ts#L77-L125) - Slightly improved `child_process#execFile`

0 comments on commit b83beea

Please sign in to comment.