Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/msaaddev/node-async-exec
🎲 Run shell command with exec asynchronously
https://github.com/msaaddev/node-async-exec
asynchronous asynchronously exec nodejs shell
Last synced: 6 days ago
JSON representation
🎲 Run shell command with exec asynchronously
- Host: GitHub
- URL: https://github.com/msaaddev/node-async-exec
- Owner: msaaddev
- License: mit
- Created: 2021-06-06T19:39:10.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T19:30:28.000Z (over 1 year ago)
- Last Synced: 2024-10-30T18:19:59.040Z (19 days ago)
- Topics: asynchronous, asynchronously, exec, nodejs, shell
- Language: JavaScript
- Homepage: https://twitter.com/msaaddev
- Size: 59.6 KB
- Stars: 7
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: license
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# 🎲 node-async-exec
![version](https://img.shields.io/npm/v/node-async-exec?color=%2FD566)
![downloads](https://img.shields.io/npm/dt/node-async-exec?color=2FD566)
![license](https://img.shields.io/npm/l/node-async-exec?color=2FD566)A package that runs exec command asynchronously and also changes directory if needed to run commands.
## Features
- Asynchronously run a shell command.
- Run a shell command/commands inside a specific directory.
- Uses [exec node method](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) and [process.chdir](https://nodejs.org/api/process.html#process_process_chdir_directory) under the hood.
- Can be used to build CLI and Node.js based tools.
## Install
```sh
# install the package
npm install node-async-exec
```
## Usage
- Run a shell command
```js
const exec = require('node-async-exec');(async () => {
try {
await exec({ cmd: `touch example.md` })
} catch (err) {
console.log(err);
}
})()
```- Change directory and run a command inside of it
```js
const exec = require('node-async-exec');(async () => {
try {
await exec({
path: `/Users/saadirfan/GitHub`,
cmd: `touch example.md`
})
} catch (err) {
console.log(err);
}
})()
```- Change directory and run a number of shell command inside that directory
```js
const exec = require('node-async-exec');(async () => {
try {
const commands = [`git init`, `touch example.md`];
await exec({
path: `/Users/saadirfan/GitHub`,
cmd: commands
})
} catch (err) {
console.log(err);
}
})()
```## ⚡️ Other Projects
I have curated a [detailed list](https://github.com/msaaddev/open-source) of all the open-source projects I have authored. Do take out a moment and take a look.
## 🔑 License & Conduct
- MIT © [Saad Irfan](https://github.com/msaaddev)
- [Code of Conduct](https://github.com/msaaddev/node-async-exec/blob/master/code-of-conduct.md)