diff --git a/.gitignore b/.gitignore index f55f145..a048be2 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,6 @@ node_modules # InteliJ .idea +.vscode -lib/ \ No newline at end of file +lib/ diff --git a/README.md b/README.md index 2aa20f9..be9e115 100644 --- a/README.md +++ b/README.md @@ -24,30 +24,55 @@ Unstable ## Getting started -Install the client using npm +### Install & run Eventstore on localhost - npm install eventstore-node - -Examples +See http://docs.geteventstore.com/introduction/3.9.0/ . + +### 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 .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 To run the tests you will need