From 51d5782387023c69c04d123451de1d593afb84b7 Mon Sep 17 00:00:00 2001 From: Robert on Asus 305 Date: Sat, 29 Oct 2016 14:30:39 -0700 Subject: [PATCH 1/3] Getting started example --- .gitignore | 3 ++- README.md | 66 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 17 deletions(-) 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..e694e0a 100644 --- a/README.md +++ b/README.md @@ -24,30 +24,64 @@ 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 +1. 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); + }); +``` +2. Create ```package.json```: + +```json +{ + "name": "hello", + "version": "1.0.0", + "main": "app.js", + "dependencies": { + "eventstore-node": "latest", + "uuid": "latest" + } +} +``` + +3. ```npm install``` + +4. ```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 From 69842b8d44b5f7b39ee51cbd63e6dece441ed4c6 Mon Sep 17 00:00:00 2001 From: Robert on Asus 305 Date: Sat, 29 Oct 2016 14:34:29 -0700 Subject: [PATCH 2/3] Getting Started. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e694e0a..a3159df 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ See http://docs.geteventstore.com/introduction/3.9.0/ . ### Example: Storing an event -1. Save to ```app.js:``` +Save to ```app.js:``` ```javascript var esClient = require('eventstore-node'); @@ -60,7 +60,7 @@ esConnection.appendToStream(streamName, esClient.expectedVersion.any, event) console.log(err); }); ``` -2. Create ```package.json```: +Create ```package.json```: ```json { @@ -74,9 +74,9 @@ esConnection.appendToStream(streamName, esClient.expectedVersion.any, event) } ``` -3. ```npm install``` +```npm install``` -4. ```node app.js``` +```node app.js``` ## Porting .Net Task to Node.js From 4f066bf00e51b38053d1e1c35154861b840ff20f Mon Sep 17 00:00:00 2001 From: Robert on Asus 305 Date: Sat, 29 Oct 2016 16:41:08 -0700 Subject: [PATCH 3/3] Brevity. --- README.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a3159df..be9e115 100644 --- a/README.md +++ b/README.md @@ -60,24 +60,15 @@ esConnection.appendToStream(streamName, esClient.expectedVersion.any, event) console.log(err); }); ``` -Create ```package.json```: + +Run: ```json -{ - "name": "hello", - "version": "1.0.0", - "main": "app.js", - "dependencies": { - "eventstore-node": "latest", - "uuid": "latest" - } -} +npm install uuid +npm install eventstore-node +node app.js ``` -```npm install``` - -```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.