EventStoreDB is the open-source, functional database with Complex Event Processing in Javascript.
This is the repository for the NodeJS client for EventStoreDB 20+ and uses gRPC as the communication protocol.
Note: This client is currently under active development and further API changes are expected. Feedback is very welcome.
# Yarn
$ yarn add @eventstore/db-client
# NPM
$ npm install --save @eventstore/db-client
This client is compatible with version 20.6.1
upwards.
Server setup instructions can be found here EventStoreDB Docs, follow the docker setup for the simplest configuration.
The following snippet showcases a simple example where we form a connection, then write and read events from the server.
const {
EventData,
EventStoreConnection,
writeEventsToStream,
readEventsFromStream,
} = require("@eventstore/db-client");
const connection = EventStoreConnection.builder()
.insecure()
.singleNodeConnection("localhost:2113");
async function simpleTest() {
const streamName = "es_supported_clients";
const event = EventData.json("grpc-client", {
languages: ["typescript", "javascript"],
runtime: "NodeJS",
}).build();
const writeResult = await writeEventsToStream(streamName)
.send(event)
.execute(connection);
const events = await readEventsFromStream(streamName)
.fromStart()
.forward()
.count(10)
.execute(connection);
events.forEach(doSomethingProductive);
}
import {
EventData,
EventStoreConnection,
writeEventsToStream,
readEventsFromStream,
} from "@eventstore/db-client";
const connection = EventStoreConnection.builder()
.insecure()
.singleNodeConnection("localhost:2113");
async function simpleTest(): Promise<void> {
const streamName = "es_supported_clients";
const event = EventData.json("grpc-client", {
languages: ["typescript", "javascript"],
runtime: "NodeJS",
}).build();
const writeResult = await writeEventsToStream(streamName)
.send(event)
.execute(connection);
const events = await readEventsFromStream(streamName)
.fromStart()
.forward()
.count(10)
.execute(connection);
events.forEach(doSomethingProductive);
}
This project uses Yarn as a build tool. The following shell command lines should get you started:
$ yarn
$ yarn build
Tests are written using Jest and require Docker and Docker Compose to be installed.
$ yarn test
Specific docker images can be specified via the enviroment variable EVENTSTORE_IMAGE
.
$ yarn cross-env EVENTSTORE_IMAGE=77d63f3f0ab3 jest
Information on support can be found here: EventStoreDB Support
Documentation for EventStoreDB can be found here: EventStoreDB Docs
Bear in mind that this client is not yet properly documented. We are working hard on a new version of the documentation.
We have a community discussion space at EventStoreDB Discuss.
Development is done on the master
branch. We attempt to do our best to ensure that the history remains clean and to do so, we generally ask contributors to squash their commits into a set or single logical commit.