{"id":15501619,"url":"https://github.com/thenativeweb/node-eventstore","last_synced_at":"2025-12-15T03:29:30.381Z","repository":{"id":43759481,"uuid":"2306324","full_name":"thenativeweb/node-eventstore","owner":"thenativeweb","description":"EventStore Implementation in node.js","archived":false,"fork":false,"pushed_at":"2022-02-19T07:26:46.000Z","size":1078,"stargazers_count":539,"open_issues_count":26,"forks_count":115,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-28T12:07:45.933Z","etag":null,"topics":["domain-driven-design","event-sourcing","eventstore","eventstream","javascript","nodejs"],"latest_commit_sha":null,"homepage":"http://eventstore.js.org/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thenativeweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-01T06:54:16.000Z","updated_at":"2025-03-13T01:29:03.000Z","dependencies_parsed_at":"2022-07-21T01:18:37.726Z","dependency_job_id":null,"html_url":"https://github.com/thenativeweb/node-eventstore","commit_stats":null,"previous_names":["jamuhl/nodeeventstore","adrai/node-eventstore"],"tags_count":88,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-eventstore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-eventstore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-eventstore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-eventstore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thenativeweb","download_url":"https://codeload.github.com/thenativeweb/node-eventstore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182365,"owners_count":20897380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-driven-design","event-sourcing","eventstore","eventstream","javascript","nodejs"],"created_at":"2024-10-02T09:05:03.019Z","updated_at":"2025-12-15T03:29:25.346Z","avatar_url":"https://github.com/thenativeweb.png","language":"JavaScript","readme":"# ⚠️ IMPORTANT NEWS! 📰\n\nI’ve been dealing with CQRS, event-sourcing and DDD long enough now that I don’t need working with it anymore unfortunately, so at least for now this my formal farewell!\n\nI want to thank everyone who has contributed in one way or another.\nEspecially...\n\n- [Jan](https://github.com/jamuhl), who introduced me to this topic.\n- [Dimitar](https://github.com/nanov), one of the last bigger contributors and maintainer.\n- My last employer, who gave me the possibility to use all these CQRS modules in a big Cloud-System.\n- My family and friends, who very often came up short.\n\nFinally, I would like to thank [Golo Roden](https://github.com/goloroden), who was there very early at the beginning of my CQRS/ES/DDD journey and is now here again to take over these modules.\n\nGolo Roden is the founder, CTO and managing director of [the native web](https://www.thenativeweb.io/), a company specializing in native web technologies. Among other things, he also teaches CQRS/ES/DDD etc. and based on his vast knowledge, he brought wolkenkit to life.\n[wolkenkit](https://wolkenkit.io) is a CQRS and event-sourcing framework based on Node.js. It empowers you to build and run scalable distributed web and cloud services that process and store streams of domain events.\n\nWith this step, I can focus more on [i18next](https://www.i18next.com), [locize](https://locize.com) and [localistars](https://localistars.com). I'm happy about that. 😊\n\nSo, there is no end, but the start of a new phase for my CQRS modules. 😉\n\nI wish you all good luck on your journey.\n\nWho knows, maybe we'll meet again in a github issue or PR at [i18next](https://github.com/i18next/i18next) 😉\n\n\n[Adriano Raiano](https://twitter.com/adrirai)\n\n---\n\n# Introduction\n\n[![JS.ORG](https://img.shields.io/badge/js.org-eventstore-ffb400.svg?style=flat-square)](http://js.org)\n[![travis](https://img.shields.io/travis/adrai/node-eventstore.svg)](https://travis-ci.org/adrai/node-eventstore) [![npm](https://img.shields.io/npm/v/eventstore.svg)](https://npmjs.org/package/eventstore)\n\nThe project goal is to provide an eventstore implementation for node.js:\n\n- load and store events via EventStream object\n- event dispatching to your publisher (optional)\n- supported Dbs (inmemory, mongodb, redis, tingodb, elasticsearch, azuretable, dynamodb)\n- snapshot support\n- query your events\n\n# Consumers\n\n- [cqrs-domain](https://github.com/adrai/node-cqrs-domain)\n- [cqrs](https://github.com/leogiese/cqrs)\n\n# Installation\n\n    npm install eventstore\n\n# Usage\n\n## Require the module and init the eventstore:\n```javascript\nvar eventstore = require('eventstore');\n\nvar es = eventstore();\n```\n\nBy default the eventstore will use an inmemory Storage.\n\n### Logging\n\nFor logging and debugging you can use [debug](https://github.com/visionmedia/debug) by [TJ Holowaychuk](https://github.com/visionmedia)\n\nsimply run your process with\n\n    DEBUG=eventstore* node app.js\n\n## Provide implementation for storage\n\nexample with mongodb:\n\n```javascript\nvar es = require('eventstore')({\n  type: 'mongodb',\n  host: 'localhost',                             // optional\n  port: 27017,                                   // optional\n  dbName: 'eventstore',                          // optional\n  eventsCollectionName: 'events',                // optional\n  snapshotsCollectionName: 'snapshots',          // optional\n  transactionsCollectionName: 'transactions',    // optional\n  timeout: 10000,                                // optional\n  // emitStoreEvents: true                       // optional, by default no store events are emitted\n  // maxSnapshotsCount: 3                        // optional, defaultly will keep all snapshots\n  // authSource: 'authedicationDatabase'         // optional\n  // username: 'technicalDbUser'                 // optional\n  // password: 'secret'                          // optional\n  // url: 'mongodb://user:pass@host:port/db?opts // optional\n  // positionsCollectionName: 'positions'        // optional, defaultly wont keep position\n});\n```\n\nexample with redis:\n```javascript\nvar es = require('eventstore')({\n  type: 'redis',\n  host: 'localhost',                          // optional\n  port: 6379,                                 // optional\n  db: 0,                                      // optional\n  prefix: 'eventstore',                       // optional\n  eventsCollectionName: 'events',             // optional\n  snapshotsCollectionName: 'snapshots',       // optional\n  timeout: 10000                              // optional\n  // emitStoreEvents: true,                   // optional, by default no store events are emitted\n  // maxSnapshotsCount: 3                     // optional, defaultly will keep all snapshots\n  // password: 'secret'                       // optional\n});\n```\n\nexample with tingodb:\n```javascript\nvar es = require('eventstore')({\n  type: 'tingodb',\n  dbPath: '/path/to/my/db/file',              // optional\n  eventsCollectionName: 'events',             // optional\n  snapshotsCollectionName: 'snapshots',       // optional\n  transactionsCollectionName: 'transactions', // optional\n  timeout: 10000,                             // optional\n  // emitStoreEvents: true,                   // optional, by default no store events are emitted\n  // maxSnapshotsCount: 3                     // optional, defaultly will keep all snapshots\n});\n```\n\nexample with elasticsearch:\n```javascript\nvar es = require('eventstore')({\n  type: 'elasticsearch',\n  host: 'localhost:9200',                     // optional\n  indexName: 'eventstore',                    // optional\n  eventsTypeName: 'events',                   // optional\n  snapshotsTypeName: 'snapshots',             // optional\n  log: 'warning',                             // optional\n  maxSearchResults: 10000,                    // optional\n  // emitStoreEvents: true,                   // optional, by default no store events are emitted\n  // maxSnapshotsCount: 3                     // optional, defaultly will keep all snapshots\n});\n```\n\nexample with custom elasticsearch client (e.g. with AWS ElasticSearch client. Note ``` http-aws-es ``` package usage in this example):\n```javascript\nvar elasticsearch = require('elasticsearch');\n\nvar esClient = = new elasticsearch.Client({\n  hosts: 'SOMETHING.es.amazonaws.com',\n  connectionClass: require('http-aws-es'),\n  amazonES: {\n    region: 'us-east-1',\n    accessKey: 'REPLACE_AWS_accessKey',\n    secretKey: 'REPLACE_AWS_secretKey'\n  }\n});\n\nvar es = require('eventstore')({\n  type: 'elasticsearch',\n  client: esClient,\n  indexName: 'eventstore',\n  eventsTypeName: 'events',\n  snapshotsTypeName: 'snapshots',\n  log: 'warning',\n  maxSearchResults: 10000\n});\n```\n\nexample with azuretable:\n```javascript\nvar es = require('eventstore')({\n  type: 'azuretable',\n  storageAccount: 'nodeeventstore',\n  storageAccessKey: 'aXJaod96t980AbNwG9Vh6T3ewPQnvMWAn289Wft9RTv+heXQBxLsY3Z4w66CI7NN12+1HUnHM8S3sUbcI5zctg==',\n  storageTableHost: 'https://nodeeventstore.table.core.windows.net/',\n  eventsTableName: 'events',               // optional\n  snapshotsTableName: 'snapshots',         // optional\n  timeout: 10000,                          // optional\n  emitStoreEvents: true                    // optional, by default no store events are emitted\n});\n```\n\nexample with dynamodb:\n```javascript\nvar es = require('eventstore')({\n    type: 'dynamodb',\n    eventsTableName: 'events',                  // optional\n    snapshotsTableName: 'snapshots',            // optional\n    undispatchedEventsTableName: 'undispatched' // optional\n    EventsReadCapacityUnits: 1,                 // optional\n    EventsWriteCapacityUnits: 3,                // optional\n    SnapshotReadCapacityUnits: 1,               // optional\n    SnapshotWriteCapacityUnits: 3,              // optional\n    UndispatchedEventsReadCapacityUnits: 1,     // optional\n    UndispatchedEventsReadCapacityUnits: 1,     // optional\n    useUndispatchedEventsTable: true            // optional\n    eventsTableStreamEnabled: false             // optional\n    eventsTableStreamViewType: 'NEW_IMAGE',     // optional\n    emitStoreEvents: true                       // optional, by default no store events are emitted\n});\n```\n\nDynamoDB credentials are obtained by eventstore either from environment vars or credentials file. For setup see [AWS Javascript SDK](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html).\n\nDynamoDB provider supports [DynamoDB local](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) for local development via the AWS SDK `endpoint` option. Just set the `$AWS_DYNAMODB_ENDPOINT` (or `%AWS_DYNAMODB_ENDPOINT%` in Windows) environment variable to point to your running instance of Dynamodb local like this:\n\n    $ export AWS_DYNAMODB_ENDPOINT=http://localhost:8000\n\nOr on Windows:\n\n    \u003e set AWS_DYNAMODB_ENDPOINT=http://localhost:8000\n\nThe **useUndispatchedEventsTable** option to available for those who prefer to use DyanmoDB.Streams to pull events from the store instead of the UndispatchedEvents table. The default is true. Setting this option to false will result in the UndispatchedEvents table not being created at all, the getUndispatchedEvents method will always return an empty array, and the setEventToDispatched will effectively do nothing.\n\nRefer to [StreamViewType](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_StreamSpecification.html#DDB-Type-StreamSpecification-StreamViewType) for a description of the **eventsTableStreamViewType** option\n\n## Built-in event publisher (optional)\n\nif defined the eventstore will try to publish AND set event do dispatched on its own...\n\n### sync interface\n```javascript\nes.useEventPublisher(function(evt) {\n  // bus.emit('event', evt);\n});\n```\n\n### async interface\n\n```javascript\nes.useEventPublisher(function(evt, callback) {\n  // bus.sendAndWaitForAck('event', evt, callback);\n});\n```\n\n## catch connect and disconnect events\n\n```javascript\nes.on('connect', function() {\n  console.log('storage connected');\n});\n\nes.on('disconnect', function() {\n  console.log('connection to storage is gone');\n});\n```\n\n## define event mappings [optional]\n\nDefine which values should be mapped/copied to the payload event.\n\n```javascript\nes.defineEventMappings({\n  id: 'id',\n  commitId: 'commitId',\n  commitSequence: 'commitSequence',\n  commitStamp: 'commitStamp',\n  streamRevision: 'streamRevision'\n});\n```\n\n## initialize\n```javascript\nes.init(function (err) {\n  // this callback is called when all is ready...\n});\n\n// or\n\nes.init(); // callback is optional\n```\n\n## working with the eventstore\n\n### get the eventhistory (of an aggregate)\n\n```javascript\nes.getEventStream('streamId', function(err, stream) {\n  var history = stream.events; // the original event will be in events[i].payload\n\n  // myAggregate.loadFromHistory(history);\n});\n```\n\nor\n\n```javascript\nes.getEventStream({\n  aggregateId: 'myAggregateId',\n  aggregate: 'person',          // optional\n  context: 'hr'                 // optional\n}, function(err, stream) {\n  var history = stream.events; // the original event will be in events[i].payload\n\n  // myAggregate.loadFromHistory(history);\n});\n```\n\n'streamId' and 'aggregateId' are the same...\nIn ddd terms aggregate and context are just to be more precise in language.\nFor example you can have a 'person' aggregate in the context 'human ressources' and a 'person' aggregate in the context of 'business contracts'...\nSo you can have 2 complete different aggregate instances of 2 complete different aggregates (but perhaps with same name) in 2 complete different contexts\n\nyou can request an eventstream even by limit the query with a 'minimum revision number' and a 'maximum revision number'\n\n```javascript\nvar revMin = 5,\n    revMax = 8; // if you omit revMax or you define it as -1 it will retrieve until the end\n\nes.getEventStream('streamId' || {/* query */}, revMin, revMax, function(err, stream) {\n  var history = stream.events; // the original event will be in events[i].payload\n\n  // myAggregate.loadFromHistory(history);\n});\n```\n\nstore a new event and commit it to store\n\n```javascript\nes.getEventStream('streamId', function(err, stream) {\n  stream.addEvent({ my: 'event' });\n  stream.addEvents([{ my: 'event2' }]);\n\n  stream.commit();\n\n  // or\n\n  stream.commit(function(err, stream) {\n    console.log(stream.eventsToDispatch); // this is an array containing all added events in this commit.\n  });\n});\n```\n\nif you defined an event publisher function the committed event will be dispatched to the provided publisher\n\nif you just want to load the last event as stream you can call getLastEventAsStream instead of ´getEventStream´.\n\n## working with snapshotting\n\nget snapshot and eventhistory from the snapshot point\n\n```javascript\nes.getFromSnapshot('streamId', function(err, snapshot, stream) {\n  var snap = snapshot.data;\n  var history = stream.events; // events history from given snapshot\n\n  // myAggregate.loadSnapshot(snap);\n  // myAggregate.loadFromHistory(history);\n});\n```\n\nor\n\n```javascript\nes.getFromSnapshot({\n  aggregateId: 'myAggregateId',\n  aggregate: 'person',          // optional\n  context: 'hr'                 // optional\n}, function(err, snapshot, stream) {\n  var snap = snapshot.data;\n  var history = stream.events; // events history from given snapshot\n\n  // myAggregate.loadSnapshot(snap);\n  // myAggregate.loadFromHistory(history);\n});\n```\n\nyou can request a snapshot and an eventstream even by limit the query with a 'maximum revision number'\n\n```javascript\nvar revMax = 8; // if you omit revMax or you define it as -1 it will retrieve until the end\n\nes.getFromSnapshot('streamId' || {/* query */}, revMax, function(err, snapshot, stream) {\n  var snap = snapshot.data;\n  var history = stream.events; // events history from given snapshot\n\n  // myAggregate.loadSnapshot(snap);\n  // myAggregate.loadFromHistory(history);\n});\n```\n\n\ncreate a snapshot point\n\n```javascript\nes.getFromSnapshot('streamId', function(err, snapshot, stream) {\n\n  var snap = snapshot.data;\n  var history = stream.events; // events history from given snapshot\n\n  // myAggregate.loadSnapshot(snap);\n  // myAggregate.loadFromHistory(history);\n\n  // create a new snapshot depending on your rules\n  if (history.length \u003e myLimit) {\n    es.createSnapshot({\n      streamId: 'streamId',\n      data: myAggregate.getSnap(),\n      revision: stream.lastRevision,\n      version: 1 // optional\n    }, function(err) {\n      // snapshot saved\n    });\n\n    // or\n\n    es.createSnapshot({\n      aggregateId: 'myAggregateId',\n      aggregate: 'person',          // optional\n      context: 'hr'                 // optional\n      data: myAggregate.getSnap(),\n      revision: stream.lastRevision,\n      version: 1 // optional\n    }, function(err) {\n      // snapshot saved\n    });\n  }\n\n  // go on: store new event and commit it\n  // stream.addEvents...\n\n});\n```\n\nYou can automatically clean older snapshots by configuring the number of snapshots to keep with `maxSnapshotsCount` in `eventstore` options.\n\n## own event dispatching (no event publisher function defined)\n\n```javascript\nes.getUndispatchedEvents(function(err, evts) {\n  // or es.getUndispatchedEvents('streamId', function(err, evts) {\n  // or es.getUndispatchedEvents({ // free choice (all, only context, only aggregate, only aggregateId...)\n  //                                context: 'hr',\n  //                                aggregate: 'person',\n  //                                aggregateId: 'uuid'\n  //                              }, function(err, evts) {\n\n  // all undispatched events\n  console.log(evts);\n\n  // dispatch it and set the event as dispatched\n\n  for (var e in evts) {\n    var evt = evts[r];\n    es.setEventToDispatched(evt, function(err) {});\n    // or\n    es.setEventToDispatched(evt.id, function(err) {});\n  }\n\n});\n```\n\n## query your events\n\nfor replaying your events or for rebuilding a viewmodel or just for fun...\n\nskip, limit always optional\n```javascript\nvar skip = 0,\n    limit = 100; // if you omit limit or you define it as -1 it will retrieve until the end\n\nes.getEvents(skip, limit, function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n\n// or\n\nes.getEvents('streamId', skip, limit, function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n\n// or\n\nes.getEvents({ // free choice (all, only context, only aggregate, only aggregateId...)\n  context: 'hr',\n  aggregate: 'person',\n  aggregateId: 'uuid'\n}, skip, limit, function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n```\n\nby revision\n\nrevMin, revMax always optional\n\n```javascript\nvar revMin = 5,\n    revMax = 8; // if you omit revMax or you define it as -1 it will retrieve until the end\n\nes.getEventsByRevision('streamId', revMin, revMax, function(err, evts) {});\n\n// or\n\nes.getEventsByRevision({\n  aggregateId: 'myAggregateId',\n  aggregate: 'person',          // optional\n  context: 'hr'                 // optional\n}, revMin, revMax, function(err, evts) {});\n```\nby commitStamp\n\nskip, limit always optional\n\n```javascript\nvar skip = 0,\n    limit = 100; // if you omit limit or you define it as -1 it will retrieve until the end\n\nes.getEventsSince(new Date(2015, 5, 23), skip, limit, function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n\n// or\n\nes.getEventsSince(new Date(2015, 5, 23), limit, function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n\n// or\n\nes.getEventsSince(new Date(2015, 5, 23), function(err, evts) {\n  // if (events.length === amount) {\n  //   events.next(function (err, nextEvts) {}); // just call next to retrieve the next page...\n  // } else {\n  //   // finished...\n  // }\n});\n```\n\n## streaming your events\nSome databases support streaming your events, the api is similar to the query one\n\nskip, limit always optional\n\n```javascript\nvar skip = 0,\n    limit = 100; // if you omit limit or you define it as -1 it will retrieve until the end\n\nvar stream = es.streamEvents(skip, limit);\n// or\nvar stream = es.streamEvents('streamId', skip, limit);\n// or by commitstamp\nvar stream = es.streamEventsSince(new Date(2015, 5, 23), skip, limit);\n// or by revision\nvar stream = es.streamEventsByRevision({\n  aggregateId: 'myAggregateId',\n  aggregate: 'person',\n  context: 'hr',\n});\n\nstream.on('data', function(e) {\n  doSomethingWithEvent(e);\n});\n\nstream.on('end', function() {\n  console.log('no more evets');\n});\n\n// or even better\nstream.pipe(myWritableStream);\n```\n\ncurrently supported by:\n\n1. mongodb\n\n## get the last event\nfor example to obtain the last revision nr\n```javascript\nes.getLastEvent('streamId', function(err, evt) {\n});\n\n// or\n\nes.getLastEvent({ // free choice (all, only context, only aggregate, only aggregateId...)\n  context: 'hr',\n  aggregate: 'person',\n  aggregateId: 'uuid'\n} function(err, evt) {\n});\n```\n\n## obtain a new id\n\n```javascript\nes.getNewId(function(err, newId) {\n  if(err) {\n    console.log('ohhh :-(');\n    return;\n  }\n\n  console.log('the new id is: ' + newId);\n});\n```\n\n## position of event in store\n\nsome db implementations support writing the position of the event in the whole store additional to the streamRevision.\n\ncurrently those implementations support this:\n\n1. inmemory ( by setting ```trackPosition`` option )\n1. mongodb ( by setting ```positionsCollectionName``` option)\n\n## special scaling handling with mongodb\n\nInserting multiple events (documents) in mongodb, is not atomic.\nFor the eventstore tries to repair itself when calling `getEventsByRevision`.\nBut if you want you can trigger this from outside:\n\n```javascript\nes.store.getPendingTransactions(function(err, txs) {\n  if(err) {\n    console.log('ohhh :-(');\n    return;\n  }\n\n  // txs is an array of objects like:\n  // {\n  //   _id: '/* the commitId of the committed event stream */',\n  //   events: [ /* all events of the committed event stream */ ],\n  //   aggregateId: 'aggregateId',\n  //   aggregate: 'aggregate', // optional\n  //   context: 'context'      // optional\n  // }\n\n  es.store.getLastEvent({\n    aggregateId: txs[0].aggregateId,\n    aggregate: txs[0].aggregate, // optional\n    context: txs[0].context      // optional\n  }, function (err, lastEvent) {\n    if(err) {\n      console.log('ohhh :-(');\n      return;\n    }\n\n    es.store.repairFailedTransaction(lastEvent, function (err) {\n      if(err) {\n        console.log('ohhh :-(');\n        return;\n      }\n\n      console.log('everything is fine');\n    });\n  });\n});\n```\n## Catch before and after eventstore events\nOptionally the eventstore can emit brefore and after events, to enable this feature set the `emitStoreEvents` to true.\n\n```javascript\nvar eventstore = require('eventstore');\nvar es = eventstore({\n  emitStoreEvents: true,\n});\n\nes.on('before-clear', function({milliseconds}) {});\nes.on('after-clear', function({milliseconds}) {});\n\nes.on('before-get-next-positions', function({milliseconds, arguments: [positions]}) {});\nes.on('after-get-next-positions', function({milliseconds, arguments: [positions]}) {});\n\nes.on('before-add-events', function({milliseconds, arguments: [events]}) {});\nes.on('after-add-events', function(milliseconds, arguments: [events]) {});\n\nes.on('before-get-events', function({milliseconds, arguments: [query, skip, limit]}) {});\nes.on('after-get-events', function({milliseconds, arguments: [query, skip, limit]}) {});\n\nes.on('before-get-events-since', function({milliseconds, arguments: [milliseconds, date, skip, limit]}) {});\nes.on('after-get-events-since', function({milliseconds, arguments: [date, skip, limit]}) {});\n\nes.on('before-get-events-by-revision', function({milliseconds, arguments: [query, revMin, revMax]}) {});\nes.on('after-get-events-by-revision', function({milliseconds, arguments, [query, revMin, revMax]}) {});\n\nes.on('before-get-last-event', function({milliseconds, arguments: [query]}) {});\nes.on('after-get-last-event', function({milliseconds, arguments: [query]}) {});\n\nes.on('before-get-undispatched-events', function({milliseconds, arguments: [query]}) {});\nes.on('after-get-undispatched-events', function({milliseconds, arguments: [query]}) {});\n\nes.on('before-set-event-to-dispatched', function({milliseconds, arguments: [id]}) {});\nes.on('after-set-event-to-dispatched', function({milliseconds, arguments: [id]}) {});\n\nes.on('before-add-snapshot', function({milliseconds, arguments: [snap]}) {});\nes.on('after-add-snapshot', function({milliseconds, arguments: [snap]}) {});\n\nes.on('before-clean-snapshots', function({milliseconds, arguments: [query]}) {});\nes.on('after-clean-snapshots', function({milliseconds, arguments: [query]}) {});\n\nes.on('before-get-snapshot', function({milliseconds, arguments: [query, revMax]}) {});\nes.on('after-get-snapshot', function({milliseconds, arguments: [query, revMax]}) {});\n\nes.on('before-remove-transactions', function({milliseconds}, arguments: [event]) {});\nes.on('after-remove-transactions', function({milliseconds}, arguments: [event]) {});\n\nes.on('before-get-pending-transactions', function({milliseconds}) {});\nes.on('after-get-pending-transactions', function({milliseconds}) {});\n\nes.on('before-repair-failed-transactions', function({milliseconds, arguments: [lastEvt]}) {});\nes.on('after-repair-failed-transactions', function({milliseconds, arguments: [lastEvt]}) {});\n\nes.on('before-remove-tables', function({milliseconds}) {});\nes.on('after-remove-tables', function({milliseconds}) {});\n\nes.on('before-stream-events', function({milliseconds, arguments: [query, skip, limit]}) {});\nes.on('after-stream-events', function({milliseconds, arguments: [query, skip, limit]}) {});\n\nes.on('before-stream-events-since', function({milliseconds, arguments: [date, skip, limit]}) {});\nes.on('after-stream-events-since', function({milliseconds, arguments: [date, skip, limit]}) {});\n\nes.on('before-get-event-stream', function({milliseconds, arguments: [query, revMin, revMax]}) {});\nes.on('after-get-event-stream', function({milliseconds, arguments: [query, revMin, revMax]}) {});\n\nes.on('before-get-from-snapshot', function({milliseconds, arguments: [query, revMax]}) {});\nes.on('after-get-from-snapshot', function({milliseconds, arguments: [query, revMax]}) {});\n\nes.on('before-create-snapshot', function({milliseconds, arguments: [obj]}) {});\nes.on('after-create-snapshot', function({milliseconds, arguments: [obj]}) {});\n\nes.on('before-commit', function({milliseconds, arguments: [eventstream]}) {});\nes.on('after-commit', function({milliseconds, arguments: [eventstream]}) {});\n\nes.on('before-get-last-event-as-stream', function({milliseconds, arguments: [query]}) {});\nes.on('after-get-last-event-as-stream', function({milliseconds, arguments: [query]}) {});\n```\n\n# Sample Integration\n\n- [nodeCQRS](https://github.com/jamuhl/nodeCQRS) A CQRS sample integrating eventstore\n\n# Inspiration\n\n- Jonathan Oliver's [EventStore](https://github.com/joliver/EventStore) for .net.\n\n# [Release notes](https://github.com/adrai/node-eventstore/blob/master/releasenotes.md)\n\n# Database Support\n\nCurrently these databases are supported:\n\n1. inmemory\n2. mongodb ([node-mongodb-native](https://github.com/mongodb/node-mongodb-native))\n3. redis ([redis](https://github.com/mranney/node_redis))\n4. tingodb ([tingodb](https://github.com/sergeyksv/tingodb))\n5. azuretable ([azure-storage](https://github.com/Azure/azure-storage-node))\n6. dynamodb ([aws-sdk](https://github.com/aws/aws-sdk-js))\n\n## own db implementation\n\nYou can use your own db implementation by extending this...\n\n```javascript\nvar Store = require('eventstore').Store,\n    util = require('util'),\n    _ = require('lodash');\n\nfunction MyDB(options) {\n  options = options || {};\n  Store.call(this, options);\n}\n\nutil.inherits(MyDB, Store);\n\n_.extend(MyDB.prototype, {\n\n  // ...\n\n});\n\nmodule.exports = MyDB;\n```\n\nand you can use it in this way\n\n```javascript\nvar es = require('eventstore')({\n  type: MyDB\n});\n// es.init...\n```\n\n# License\n\nCopyright (c) 2018 Adriano Raiano, Jan Muehlemann\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fnode-eventstore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenativeweb%2Fnode-eventstore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fnode-eventstore/lists"}