Skip to content

Commit 886505d

Browse files
committedDec 27, 2015
Updated readme with new changes and options
1 parent e9ca4af commit 886505d

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed
 

‎README.md

+56-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ $ npm install node-etcd@3.0.2
2222

2323
## Changes
2424

25+
- 5.0.0
26+
- Supports basic auth.
27+
- Breaking: Constructor changes
28+
- Breaking: Must provide https url to use https
29+
2530
- 4.2.1
2631
- Newer deasync fixes issues with iojs 3.3.0 and nodejs 4.0.0.
2732
- 4.1.0
@@ -76,24 +81,39 @@ $ npm install node-etcd@3.0.2
7681
## Basic usage
7782

7883
```javascript
79-
Etcd = require('node-etcd');
80-
etcd = new Etcd();
84+
var Etcd = require('node-etcd');
85+
var etcd = new Etcd();
8186
etcd.set("key", "value");
8287
etcd.get("key", console.log);
8388
```
8489

90+
Callbacks follows the default (error, result) nodejs convention:
91+
92+
```javascript
93+
function callback(err, res) {
94+
console.log("Error: ", err);
95+
console.log("Return: ", res);
96+
}
97+
etcd.get("key", callback);
98+
// Error: null
99+
// Return: { action: 'get', node: { key: '/key', value: 'value', modifiedIndex: 4, createdIndex: 4 } }
100+
```
101+
85102
## Methods
86103

87-
### Etcd([host = '127.0.0.1'], [port = '4001'], [ssloptions])
104+
### Etcd(hosts = ['127.0.0.1:4001'], [options])
88105

89106
Create a new etcd client for a single host etcd setup
90107

91108
```javascript
92109
etcd = new Etcd();
93-
etcd = new Etcd('127.0.0.1', '4001');
110+
etcd = new Etcd("127.0.0.1:4001");
111+
etcd = new Etcd("http://127.0.0.1:4001");
112+
etcd = new Etcd("https://127.0.0.1:4001");
113+
etcd = new Etcd(["http://127.0.0.1:4001"]);
94114
```
95115

96-
### Etcd(hosts, [ssloptions])
116+
### Etcd(hosts, [options])
97117

98118
Create a new etcd client for a clustered etcd setup. Client will connect to
99119
servers in random order. On failure it will try the next server. When all
@@ -103,6 +123,7 @@ retries can be controlled by adding `{ maxRetries: x }` as an option to requests
103123

104124
```javascript
105125
etcd = new Etcd(['127.0.0.1:4001','192.168.1.1:4001']);
126+
etcd = new Etcd(['http://127.0.0.1:4001','http://192.168.1.1:4001']);
106127
```
107128

108129
### .set(key, value = null, [options], [callback])
@@ -396,20 +417,44 @@ you won't get any callbacks from the request after calling `.abort()`.
396417

397418
## SSL support
398419

399-
Pass etcdclient a dictionary containing ssl options, check out http://nodejs.org/api/https.html#https_https_request_options_callback
420+
Provide `ca`, `cert`, `key` as options. Remember to use `https`-url.
400421

401422
```javascript
402-
fs = require('fs');
423+
var fs = require('fs');
403424

404-
sslopts = {
405-
ca: [ fs.readFileSync('ca.pem') ],
425+
var options = {
426+
ca: fs.readFileSync('ca.pem'),
406427
cert: fs.readFileSync('cert.pem'),
407-
key: fs.readFileSync('key.pem')
428+
key: fs.readFileSync('key.pem')
408429
};
409430

410-
etcdssl = new Etcd('localhost', '4001', sslopts);
431+
var etcdssl = new Etcd("https://localhost:4001", options);
411432
```
412433

434+
## Basic auth
435+
436+
Pass a hash containing username and password as auth option to use basic auth.
437+
438+
```javascript
439+
var auth = {
440+
user: "username",
441+
pass: "password"
442+
}
443+
444+
var etcd = new Etcd("localhost:4001", { auth: auth });
445+
```
446+
447+
## Constructor options
448+
449+
Useful constructor options include:
450+
451+
- `timeout` - Integer request timeout in milliseconds to wait for server response.
452+
- `ca` - Ca certificate
453+
- `cert` - Client certificate
454+
- `key` - Client key
455+
- `passphrase` - Client key passphrase
456+
- `auth` - A hash containing `{user: "username", pass: "password"}` for basic auth.
457+
413458
## FAQ:
414459

415460
- Are there any order of execution guarantees when doing multiple requests without using callbacks?

0 commit comments

Comments
 (0)
Please sign in to comment.