try-exec

<p align="center"> <img src="tryexec.png" width="250" /> </p>

Usage no npm install needed!

<script type="module">
  import tryExec from 'https://cdn.skypack.dev/try-exec';
</script>

README

Exec an npm script, .bin command, or other CLI commands from nodejs,
trying x times in case a condition doesn't meets

Install

npm install -D try-exec

# or

yarn add --dev try-exec

Usage

const tryExec = require('try-exec')
const isReachable = require('is-reachable')

tryExec({
  script: 'gatsby develop',
  // Check if API is reachable
  check: async () => await isReachable('cdn.contentful.com'),
})

API

tryExec(?options)

Options

max

Max attemps to check

type: Number

default: 3

interval

Delay between each attemp

type: Number (ms)

default: 1500

script

CLI script to run

type: String

default: echo "Hello World"

check

(Async) function to run when checking

type: Function

default: () => false

verbose

Log when attemps, number of each iteration and results. Could be passed a string to log.

type: Boolean|String

default: false