Go to file
Nicolas Dextraze eb56e077f9
Merge pull request #95 from aliabbasjaffri/HA-Cluster-Connectivity-Issue
🐛 Adding object reference to externalTcpIp
2020-03-02 08:46:39 -08:00
.idea Update dev dependencies 2019-11-01 11:30:06 -07:00
samples Removed some console 2019-02-18 09:12:28 -08:00
src 🐛 Adding object reference to externalTcpIp: Solves locating cluster via gossip seeds 2020-03-02 15:39:32 +01:00
test Fix #91 2019-11-02 15:40:02 -07:00
tools Fix issue with fake-server 2018-07-11 16:10:53 -07:00
.gitignore 18 - Changing all hostname to host, fixing some async issues in tests 2017-01-28 18:04:58 -08:00
index.d.ts Add missing created to RecordedEvent typescript definition 2019-11-01 12:47:03 -07:00
index.js Rename project to node-eventstore-client 2017-05-17 12:46:27 -07:00
LICENSE Initial commit 2016-03-09 11:52:01 -08:00
package-lock.json Attempt at fixing Typescript dependencies issues 2019-11-02 16:13:51 -07:00
package.json Attempt at fixing Typescript dependencies issues 2019-11-02 16:13:51 -07:00
README.md Update documentation for strict-event-emitter-types dependency 2019-05-16 11:59:56 +02:00
Vagrantfile 18 - Changing all hostname to host, fixing some async issues in tests 2017-01-28 18:04:58 -08:00
webpack.config.js Update dev dependencies 2019-11-01 11:30:06 -07:00
yarn.lock Attempt at fixing Typescript dependencies issues 2019-11-02 16:13:51 -07:00

node-eventstore-client

A port of the EventStore .Net ClientAPI to Node.js

Status

Missing features:

  • Set system settings

Areas to improve

  • Errors
    • Use codes or types to differentiate between errors
  • Performance
    • Performance hasn't been tested yet
  • Tests
    • Can always do with more tests

Getting started

Install using npm install node-eventstore-client

Dependencies

Install and run an Eventstore on localhost

See https://eventstore.org/docs/introduction/4.1.0/

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.

API Documentation

Offline

The offline documentation can be found in the module folder ./node_modules/node-eventstore-client/docs.

Online

The online documentation can be found at https://dev.nicdex.com/node-eventstore-client/docs/

Example: Storing an event

Save to app.js:

var esClient = require('node-eventstore-client');
var uuid = require('uuid');

var streamName = "testStream";
/* 
  Connecting to a single node using "tcp://localhost:1113"
  - to connect to a cluster via dns discovery use "discover://my.host:2113"
  - to connect to a cluster via gossip seeds use 
  [
    new esClient.GossipSeed({host: '192.168.1.10', port: 2113}), 
    new esClient.GossipSeed({host: '192.168.1.11', port: 2113}), 
    new esClient.GossipSeed({host: '192.168.1.12', port: 2113})
  ]
*/
var connSettings = {};  // Use defaults
var esConnection = esClient.createConnection(connSettings, "tcp://localhost:1113");
esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) {
    console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + 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);
    });

Run:

npm install uuid
npm install node-eventstore-client
node app.js

Example: Subscribing to events

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

Running the tests

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.

EventStore.ClusterNode.exe --run-projections=all --memdb certificate-file=yourcert.pfx
or
./run-node.sh --run-projections=all --memdb certificate-file=yourcert.p12

For SSL setup see:

https://eventstore.org/docs/server/setting_up_ssl/
or
https://eventstore.org/docs/server/setting_up_ssl_linux/

To execute the tests suites simply run

npm test

Porting .Net Task to Node.js

Any async commands returns a Promise object in replacement of .Net Task.

License

Ported code is released under the MIT license, see LICENSE.

Original code is released under the EventStore license and can be found at https://github.com/eventstore/eventstore.