# is-elasticsearch-running

> Small utility to verify if an Elasticsearch cluster is up and running.

Latest version **0.1.0** (published 2019-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-elasticsearch-running
pnpm add is-elasticsearch-running
yarn add is-elasticsearch-running
bun add is-elasticsearch-running
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-09-20 |
| First published | 2019-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tomas Della Vedova |
| Maintainers | delvedor |
| Keywords | elastic, elasticsearch, test, check, running |

## Links

- npm: https://www.npmjs.com/package/is-elasticsearch-running
- Repository: https://github.com/delvedor/is-elasticsearch-running
- Homepage: https://github.com/delvedor/is-elasticsearch-running#readme
- Issues: https://github.com/delvedor/is-elasticsearch-running/issues
- npm.io page: https://npm.io/package/is-elasticsearch-running

## Dependencies (1)

- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) ^7.3.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-09-20

## README

# is-elasticsearch-running

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)  [![node-ci](https://github.com/delvedor/is-elasticsearch-running/workflows/Node%20CI/badge.svg)](https://github.com/delvedor/is-elasticsearch-running/actions)

A small utility to verify if an Elasticsearch cluster is up and running.  
It's useful to sue in your test files, without the need to use `sleep` or other hacks.

## Install
```
npm i is-elasticsearch-running --save-dev
```

## Usage

### build

`is-elasticsearch-running` needs to be initialized with the client configuration, defaults to `{ node: 'http://localhost:9200' }`.

```js
const Es = require('is-elasticsearch-running')
const es = Es({ node: 'http://localhost:9200' })
```

The builder return an object with two utilities, `isRunning` and `waitCluster`.

### isRunning

Checks if Elasticsearch is running in a given moment, returns a boolean.

```js
const Es = require('is-elasticsearch-running')
const es = Es()

es.isRunning()
  .then(bool => {
    if (bool) console.log('Elasticsearch is up and running')
    else console.log('Elasticsearch is not running')
  })
```

### waitCluster

This is very useful to use at the beginning of your test suite, it send a cluster health request and waits until Elasticsearch is ready.
By default it waits for status green and uses a timeout of 50 seconds, with 5 seconds of delay between retries. In total, tries to connect to Elasticsearch 10 times before giving up.

```js
const Es = require('is-elasticsearch-running')
const es = Es()

es.waitCluster()
  .then(() => console.log('ready'))
  .catch(() => console.log('not ready'))

es.waitCluster('yellow', '30s')
  .then(() => console.log('ready'))
  .catch(() => console.log('not ready'))
```

## License

[MIT](./LICENSE)

---
_Source: https://npm.io/package/is-elasticsearch-running · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
