node-eventstore-client/README.md

117 lines
3.2 KiB
Markdown
Raw Normal View History

2016-03-09 19:52:01 +00:00
# eventstore-node
2016-03-09 20:46:15 +00:00
A port of the EventStore .Net ClientAPI to Node.js
2016-03-10 01:08:03 +00:00
## Dependencies
2016-03-09 20:46:15 +00:00
2016-03-10 01:08:03 +00:00
- Node.js >= 0.12
2016-03-17 06:15:25 +00:00
- 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`)
2016-03-09 20:46:15 +00:00
2016-03-09 23:37:08 +00:00
## Status
Unstable
2016-03-09 20:46:15 +00:00
2016-03-14 22:37:35 +00:00
### Missing features:
- Ssl connection
- Cluster connection
- Set system settings
### Incomplete
2016-03-09 20:46:15 +00:00
- Typed errors: currently most errors are direct instance of Error, which is not practical for error handling
- Performance: there's still some while loop in the code that could be problematic with node.js
- Tests: tests are only covering happy path scenarios for now
2016-03-17 06:15:25 +00:00
2016-11-08 06:09:57 +00:00
### Documentation
#### Offline
The offline documentation can be found in the module folder `./node_modules/eventstore-node/docs`.
#### Online
The online documentation can be found at [https://dev.nicdex.com/eventstore-node/docs/](https://dev.nicdex.com/eventstore-node/docs/)
2016-03-17 06:15:25 +00:00
## Getting started
2016-10-29 21:30:39 +00:00
### Install & run Eventstore on localhost
See http://docs.geteventstore.com/introduction/3.9.0/ .
### Example: Storing an event
2016-10-29 21:34:29 +00:00
Save to ```app.js:```
2016-10-29 21:30:39 +00:00
```javascript
var esClient = require('eventstore-node');
var uuid = require('uuid');
var streamName = "testStream";
var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113});
esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) {
console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port);
});
var eventId = uuid.v4();
var eventData = {
a : Math.random(),
b: uuid.v4()
};
var event = esClient.createJsonEventData(eventId, eventData, null, 'testEvent');
console.log("Appending...");
esConnection.appendToStream(streamName, esClient.expectedVersion.any, event)
.then(function(result) {
console.log("Stored event:", eventId);
console.log("Look for it at: http://localhost:2113/web/index.html#/streams/testStream");
esConnection.close();
})
.catch(function(err) {
console.log(err);
});
```
2016-10-29 23:41:08 +00:00
Run:
2016-10-29 21:30:39 +00:00
```json
2016-10-29 23:41:08 +00:00
npm install uuid
npm install eventstore-node
node app.js
2016-10-29 21:30:39 +00:00
```
### Example: Subscribing to events
2016-03-10 01:08:03 +00:00
```cd samples```
To subscribe to all events from now on (includes example of a filter which ignores events which we aren't interested in):
```node subscribe-all-events.js```
To catch up on all events ever and subscribe to all new ones from now on:
```node subscribe-catchup-all-events.js```
To generate a test event, open a separate console and run:
```node store-event.js```
2016-03-09 23:37:08 +00:00
## Running the tests
2016-03-09 20:46:15 +00:00
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.
2016-03-17 06:15:25 +00:00
EventStore.ClusterNode.exe --memdb
2016-03-09 20:46:15 +00:00
To execute the tests suites simply run
2016-03-09 20:46:15 +00:00
2016-03-10 01:08:03 +00:00
npm test
2016-03-09 23:37:08 +00:00
## Porting .Net Task to Node.js
.Net Task have been replace with Promise. When executing an async command, i.e. appendToStream you can use then/catch to wait for result/error.
2016-03-09 23:37:08 +00:00
## License
2016-03-17 06:15:25 +00:00
Ported code is released under the MIT license, see [LICENSE](https://github.com/nicdex/eventstore-node/blob/master/LICENSE).
Original code is released under the EventStore license and can be found at https://github.com/eventstore/eventstore.