Merge pull request #6 from Adaptech/master

Getting Started - example
This commit is contained in:
Nicolas Dextraze 2016-10-30 09:33:08 -07:00 committed by GitHub
commit 29ee990a0a
2 changed files with 43 additions and 17 deletions

3
.gitignore vendored
View File

@ -34,5 +34,6 @@ node_modules
# InteliJ # InteliJ
.idea .idea
.vscode
lib/ lib/

View File

@ -24,30 +24,55 @@ Unstable
## Getting started ## Getting started
Install the client using npm ### Install & run Eventstore on localhost
npm install eventstore-node See http://docs.geteventstore.com/introduction/3.9.0/ .
Examples ### Example: Storing an event
TODO Save to ```app.js:```
```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);
});
```
Run:
```json
npm install uuid
npm install eventstore-node
node app.js
```
## Porting .Net Task to Node.js ## 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. .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.
*Example*
connection
.appendToStream('myStream', client.expectedVersion.any, events, userCredentials)
.then(function(result) {
//Do something with the WriteResult here
})
.catch(function(err) {
//Handle error here
});
## Running the tests ## Running the tests
To run the tests you will need To run the tests you will need