2020-06-16 08:25:33 +03:00
# etcd3 [![Run Tests](https://github.com/microsoft/etcd3/workflows/Run%20Tests/badge.svg)](https://github.com/microsoft/etcd3/actions?query=workflow%3A%22Run+Tests%22)
2017-04-10 08:25:42 +03:00
2021-04-11 19:19:24 +03:00
etcd3 is a high-quality, production-ready client for the Protocol Buffer-based [etcd ](https://etcd.io/ ) v3 API. It includes:
2020-06-21 19:47:40 +03:00
- [load balancing ](https://microsoft.github.io/etcd3/interfaces/ioptions.html )
- [fault handling and reconnections ](https://microsoft.github.io/etcd3/interfaces/ioptions.html#faulthandling )
- [transactions ](https://microsoft.github.io/etcd3/classes/comparatorbuilder.html )
- [software transactional memory ](https://microsoft.github.io/etcd3/classes/softwaretransaction.html )
- [high-level query builders ](https://microsoft.github.io/etcd3/classes/etcd3.html )
- [lease management ](https://microsoft.github.io/etcd3/classes/lease.html )
- [watchers ](https://microsoft.github.io/etcd3/classes/watchbuilder.html )
- [user ](https://microsoft.github.io/etcd3/classes/etcd3.html#user ) and [role ](https://microsoft.github.io/etcd3/classes/etcd3.html#role ) [mocking ](https://microsoft.github.io/etcd3/classes/etcd3.html#mock ) management
2020-11-29 07:10:17 +03:00
- [elections ](https://microsoft.github.io/etcd3/classes/election.html )
2020-06-21 19:47:40 +03:00
and is type-safe for TypeScript consumers.
2017-04-13 01:51:16 +03:00
### Quickstart
Install via:
```
npm install --save etcd3
```
2020-06-21 19:47:40 +03:00
Start building!
2017-04-13 01:51:16 +03:00
```js
const { Etcd3 } = require('etcd3');
const client = new Etcd3();
2020-06-22 00:04:33 +03:00
(async () => {
2020-06-21 19:41:00 +03:00
await client.put('foo').value('bar');
const fooValue = await client.get('foo').string();
console.log('foo was:', fooValue);
2020-06-22 00:07:50 +03:00
const allFValues = await client.getAll().prefix('f').keys();
2020-06-21 19:41:00 +03:00
console.log('all our keys starting with "f":', allFValues);
await client.delete().all();
2020-06-22 00:07:50 +03:00
})();
2017-04-13 01:51:16 +03:00
```
2017-04-10 08:25:42 +03:00
2017-04-15 00:14:28 +03:00
### API Documentation
2020-06-21 19:41:00 +03:00
Our [TypeDoc docs are available here ](https://microsoft.github.io/etcd3/classes/etcd3.html ).
2017-04-15 00:14:28 +03:00
2020-11-04 09:00:39 +03:00
Our [test cases ](https://github.com/microsoft/etcd3/tree/master/src/test/ ) are also readable.
2017-04-15 00:14:28 +03:00
2019-09-18 04:48:39 +03:00
### Running tests
```sh
$ npm install
2020-09-19 06:29:02 +03:00
$ cd src/test/containers/3.2 & & docker-compose up # in a separate shell
2019-09-18 04:48:39 +03:00
$ npm test
$ docker-compose down
```
2017-04-10 08:25:42 +03:00
### Contributing
2020-06-16 07:38:24 +03:00
Running tests for this module requires running an etcd3 server locally. The tests try to use the default port initially, and you can configure this by setting the `ETCD_ADDR` environment variable, like `export ETCD_ADDR=localhost:12345` .
2018-05-29 19:18:47 +03:00
This project has adopted the [Microsoft Open Source Code of Conduct ](https://opensource.microsoft.com/codeofconduct/ ). For more information see the [Code of Conduct FAQ ](https://opensource.microsoft.com/codeofconduct/faq/ ) or contact [opencode@microsoft.com ](mailto:opencode@microsoft.com ) with any additional questions or comments.