https://github.com/fabiospampinato/nanoexec
A tiny wrapper around "spawn" for executing a command efficiently and conveniently.
https://github.com/fabiospampinato/nanoexec
exec simple spawn tiny
Last synced: 7 months ago
JSON representation
A tiny wrapper around "spawn" for executing a command efficiently and conveniently.
- Host: GitHub
- URL: https://github.com/fabiospampinato/nanoexec
- Owner: fabiospampinato
- License: mit
- Created: 2024-03-11T22:17:07.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-13T15:12:51.000Z (over 1 year ago)
- Last Synced: 2025-07-04T05:12:24.683Z (7 months ago)
- Topics: exec, simple, spawn, tiny
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Nano Exec
A tiny wrapper around "spawn" for executing a command efficiently and conveniently.
It supports all options that `child_process.spawn` itself supports.
## Install
```sh
npm install --save nanoexec
```
## Usage
```ts
import exec from 'nanoexec';
// Execute a command successfully, directly
const result = await exec ( 'echo', ['example'] );
result.process; // => ChildProcess
result.ok; // => true, because the exit code is 0
result.code; // => 0
result.stderr; // =>
result.stdout; // =>
result.stdout.toString (); // => 'example\n'
// Execute a command successfully, going through the shell
const result = await exec ( 'echo "example"', { shell: true } );
result.process; // => ChildProcess
result.ok; // => true, because the exit code is 0
result.code; // => 0
result.stderr; // =>
result.stdout; // =>
result.stdout.toString (); // => 'example\n'
// Execute a command successfully, but with a non-zero exit code
const result = await exec ( 'node', ['-e', 'process.exit(2)'] );
result.process; // => ChildProcess
result.ok; // => false, because the exit code is not 0
result.code; // => 2
result.stderr; // =>
result.stdout; // =>
// Execute a command that throws
await exec ( 'unknowncmd' ); // => throws: Error ( 'spawn unknowncmd ENOENT' )
// Execute a command, read the subprocess immediately, and await the rest
const result = exec ( 'echo', ['example'] );
result.process; // => ChildProcess
await result.ok; // => true, because the exit code is 0
await result.code; // => 0
await result.stderr; // =>
await result.stdout; // =>
```
## License
MIT © Fabio Spampinato