1 | # node-eventstore-client
|
2 | A port of the EventStore .Net ClientAPI to Node.js
|
3 |
|
4 | ## Status
|
5 |
|
6 | ### Missing features:
|
7 |
|
8 | - Set system settings
|
9 |
|
10 | ### Areas to improve
|
11 |
|
12 | - Errors
|
13 | - Use codes or types to differentiate between errors
|
14 | - Performance
|
15 | - Performance hasn't been tested yet
|
16 | - Tests
|
17 | - Can always do with more tests
|
18 |
|
19 | ## Getting started
|
20 |
|
21 | Install using `npm install node-eventstore-client`
|
22 |
|
23 | ### Dependencies
|
24 |
|
25 | - Node.js >= 4.0
|
26 | - Modules: [long](https://www.npmjs.org/package/long), [protobufjs](https://www.npmjs.org/package/protobufjs), [uuid](https://www.npmjs.org/package/uuid) (installed via `npm install`)
|
27 |
|
28 | ### Install and run an Eventstore on localhost
|
29 |
|
30 | See https://eventstore.org/docs/introduction/4.1.0/
|
31 |
|
32 | *Note: If you are using a version of EventStore prior to 3.9.4, you need to use version 0.1.x of this package `npm install node-eventstore-client@^0.1`.*
|
33 |
|
34 |
|
35 | ### API Documentation
|
36 |
|
37 | #### Offline
|
38 |
|
39 | The offline documentation can be found in the module folder `./node_modules/node-eventstore-client/docs`.
|
40 |
|
41 | #### Online
|
42 |
|
43 | The online documentation can be found at [https://dev.nicdex.com/node-eventstore-client/docs/](https://dev.nicdex.com/node-eventstore-client/docs/)
|
44 |
|
45 | ### Example: Storing an event
|
46 |
|
47 | Save to ```app.js:```
|
48 |
|
49 | ```javascript
|
50 | var esClient = require('node-eventstore-client');
|
51 | var uuid = require('uuid');
|
52 |
|
53 | var streamName = "testStream";
|
54 | /*
|
55 | Connecting to a single node using "tcp://localhost:1113"
|
56 | - to connect to a cluster via dns discovery use "discover://my.host:2113"
|
57 | - to connect to a cluster via gossip seeds use
|
58 | [
|
59 | new esClient.GossipSeed({host: '192.168.1.10', port: 2113}),
|
60 | new esClient.GossipSeed({host: '192.168.1.11', port: 2113}),
|
61 | new esClient.GossipSeed({host: '192.168.1.12', port: 2113})
|
62 | ]
|
63 | */
|
64 | var connSettings = {}; // Use defaults
|
65 | var esConnection = esClient.createConnection(connSettings, "tcp://localhost:1113");
|
66 | esConnection.connect();
|
67 | esConnection.once('connected', function (tcpEndPoint) {
|
68 | console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
|
69 | });
|
70 |
|
71 | var eventId = uuid.v4();
|
72 | var eventData = {
|
73 | a : Math.random(),
|
74 | b: uuid.v4()
|
75 | };
|
76 | var event = esClient.createJsonEventData(eventId, eventData, null, 'testEvent');
|
77 | console.log("Appending...");
|
78 | esConnection.appendToStream(streamName, esClient.expectedVersion.any, event)
|
79 | .then(function(result) {
|
80 | console.log("Stored event:", eventId);
|
81 | console.log("Look for it at: http://localhost:2113/web/index.html#/streams/testStream");
|
82 | esConnection.close();
|
83 | })
|
84 | .catch(function(err) {
|
85 | console.log(err);
|
86 | });
|
87 | ```
|
88 |
|
89 | Run:
|
90 |
|
91 | ```json
|
92 | npm install uuid
|
93 | npm install node-eventstore-client
|
94 | node app.js
|
95 | ```
|
96 |
|
97 | ### Example: Subscribing to events
|
98 |
|
99 | ```cd samples```
|
100 |
|
101 | To subscribe to all events from now on (includes example of a filter which ignores events which we aren't interested in):
|
102 |
|
103 | ```node subscribe-all-events.js```
|
104 |
|
105 | To catch up on all events ever and subscribe to all new ones from now on:
|
106 |
|
107 | ```node subscribe-catchup-all-events.js```
|
108 |
|
109 | To generate a test event, open a separate console and run:
|
110 |
|
111 | ```node store-event.js```
|
112 |
|
113 | ## Running the tests
|
114 |
|
115 | To run the tests it is recommended that you use an in-memory instance of the eventstore so you don't pollute your dev instance.
|
116 |
|
117 | EventStore.ClusterNode.exe --run-projections=all --memdb –certificate-file=yourcert.pfx
|
118 | or
|
119 | ./run-node.sh --run-projections=all --memdb –certificate-file=yourcert.p12
|
120 |
|
121 | For SSL setup see:
|
122 |
|
123 | https://eventstore.org/docs/server/setting_up_ssl/
|
124 | or
|
125 | https://eventstore.org/docs/server/setting_up_ssl_linux/
|
126 |
|
127 | To execute the tests suites simply run
|
128 |
|
129 | npm test
|
130 |
|
131 | ## Porting .Net Task to Node.js
|
132 |
|
133 | Any async commands returns a [Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) object in replacement of .Net Task.
|
134 |
|
135 |
|
136 | ## License
|
137 |
|
138 | Ported code is released under the MIT license, see [LICENSE](https://github.com/nicdex/node-eventstore-client/blob/master/LICENSE).
|
139 |
|
140 | Original code is released under the EventStore license and can be found at https://github.com/eventstore/eventstore.
|
141 |
|
\ | No newline at end of file |