https://github.com/omrilotan/async-execute
🦅 Execute command in a child process
https://github.com/omrilotan/async-execute
async execute javascript script
Last synced: about 1 month ago
JSON representation
🦅 Execute command in a child process
- Host: GitHub
- URL: https://github.com/omrilotan/async-execute
- Owner: omrilotan
- License: unlicense
- Created: 2024-08-21T09:41:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-11T19:41:35.000Z (over 1 year ago)
- Last Synced: 2025-02-27T04:11:30.311Z (11 months ago)
- Topics: async, execute, javascript, script
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/async-execute
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# async-execute [](https://www.npmjs.com/package/async-execute)
## 🦅 Execute command in a child process
```js
import { execute } from "async-execute";
const commit_message = await execute("git log -1 --pretty=%B"); // Committed some changes
```
## Options
### Pipe stdout and stderr (default: false)
```js
await execute("npm t", { pipe: true });
```
### Exit process with child's exit code (default: false)
```js
await execute("npm t", { pipe: true, exit: true });
```
### Check a script exits properly
```js
let code = 0;
try {
const result = await execute("exit 2");
code = result.code;
} catch (error) {
code = error.code;
}
if (code > 0) {
// something must have gone wrong
}
```
## Any [exec option](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback) can be passed
```js
await execute("echo $API_KEY", {
env: { API_KEY: "vQQNJe7lnz4rTbYvr61VywR0wRlRzCyI" },
});
await execute("pwd", { cwd: "~/app" });
```