Command. Execution. Made. Simple.
Key features  • Table of contents  • Install  • Releases  • API
✨Since v.2.0.0
SimpleExec
is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to Modern Module.
Execute shell commands in a simpler manner using SimpleExec.
Supports sync, callback and async command execution.
Since version 1.1.0 parallel execution is also possible.
npm i simple-exec
The recommended way to get the package is to install with a package manager but you can also get the latest release here.
Synchronously runs the specified command.
import * as simple from 'simple-exec'
const result = simple.executeSync('dir /b')
if (result.error) {
console.error(result.error) // log the error
} else {
console.log(result.output) // log the contents of the directory
}
Asynchronously, with a callback runs the specified command.
import * as simple from 'simple-exec'
simple.executeCallback('node --version', (result) => {
if (result.error) {
console.error(result.error) // log the error
} else {
console.log(result.output) // log Node version
}
})
Asynchronously runs the specified command.
import * as simple from 'simple-exec'
try {
const result = await simple.execute('npm --version')
console.log(result) // log NPM version
} catch (exp) {
console.error(result.error) // log the error
}
import * as simple from 'simple-exec'
simple
.execute('npm --version')
.then((version) => {
console.log(version) // log NPM version
})
.catch((error) => {
console.error(error) // log the error
})
Asynchronously and in parallel runs the specified commands.
import * as simple from 'simple-exec'
simple
.executeParallel('npm --version', 'node --version', 'npm pack')
.then((results) => {
console.log(results) // log the results which is a string array
})
.catch((error) => {
console.error(error) // log the error
})
Asynchronously and in parallel runs the specified commands.
import * as simple from 'simple-exec'
simple
.executeParallel(['npm --version', 'node --version', 'npm pack'])
.then((results) => {
console.log(results) // log the results which is a string array
})
.catch((error) => {
console.error(error) // log the error
})
npm i && npm test