|
| 1 | +<picture> |
| 2 | + <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg"> |
| 3 | + <img alt="execa logo" src="../media/logo.svg" width="400"> |
| 4 | +</picture> |
| 5 | +<br> |
| 6 | + |
| 7 | +# π Small packages |
| 8 | + |
| 9 | +## `nano-spawn` |
| 10 | + |
| 11 | +Execa aims to be the best way to run commands on Node.js. It is [very widely used](https://github.com/sindresorhus/execa/network/dependents), [battle-tested](https://github.com/sindresorhus/execa/graphs/contributors) and has a bunch of [features](../readme.md#features). |
| 12 | + |
| 13 | +However, this means it has a relatively big package size: [](https://packagephobia.com/result?p=execa). This should not be a problem in a server-side context, such as a script, a server, or an app. But you might be in an environment requiring small packages, such as a library or a serverless function. |
| 14 | + |
| 15 | +If so, you can use [nano-spawn](https://github.com/sindresorhus/nano-spawn). It is similar, is maintained by the [same people](https://github.com/sindresorhus/nano-spawn#maintainers), has no dependencies, and a smaller package size:  [](https://packagephobia.com/result?p=nano-spawn). |
| 16 | + |
| 17 | +On the other hand, please note `nano-spawn` lacks many features from Execa: [scripts](scripts.md), [template string syntax](execution.md#template-string-syntax), [synchronous execution](execution.md#synchronous-execution), [file input/output](output.md#file-output), [binary input/output](binary.md), [advanced piping](pipe.md), [verbose mode](debugging.md#verbose-mode), [graceful](termination.md#graceful-termination) or [forceful termination](termination.md#forceful-termination), [IPC](ipc.md), [shebangs on Windows](windows.md), [and much more](https://github.com/sindresorhus/nano-spawn/issues/14). |
| 18 | + |
| 19 | +```js |
| 20 | +import spawn from 'nano-spawn'; |
| 21 | + |
| 22 | +const result = await spawn('npm', ['run', 'build']); |
| 23 | +``` |
| 24 | + |
| 25 | +### `node:child_process` |
| 26 | + |
| 27 | +Both Execa and nano-spawn are built on top of the [`node:child_process`](https://nodejs.org/api/child_process.html) core module. |
| 28 | + |
| 29 | +If you'd prefer avoiding adding any dependency, you may use `node:child_process` directly. However, you might miss some basic [features](https://github.com/sindresorhus/nano-spawn#features) that both Execa and nano-spawn provide: [proper error handling](https://github.com/sindresorhus/nano-spawn#subprocesserror), [full Windows support](https://github.com/sindresorhus/nano-spawn#windows-support), [local binaries](https://github.com/sindresorhus/nano-spawn#optionspreferlocal), [piping](https://github.com/sindresorhus/nano-spawn#subprocesspipefile-arguments-options), [lines iteration](https://github.com/sindresorhus/nano-spawn#subprocesssymbolasynciterator), [interleaved output](https://github.com/sindresorhus/nano-spawn#resultoutput), [and more](https://github.com/sindresorhus/nano-spawn#features). |
| 30 | + |
| 31 | +```js |
| 32 | +import {execFile} from 'node:child_process'; |
| 33 | +import {promisify} from 'node:util'; |
| 34 | + |
| 35 | +const pExecFile = promisify(execFile); |
| 36 | + |
| 37 | +const result = await pExecFile('npm', ['run', 'build']); |
| 38 | +``` |
| 39 | + |
| 40 | +<hr> |
| 41 | + |
| 42 | +[**Next**: π€ TypeScript](typescript.md)\ |
| 43 | +[**Previous**: π Differences with Bash and zx](bash.md)\ |
| 44 | +[**Top**: Table of contents](../readme.md#documentation) |
0 commit comments