Serve an append-only log over TCP.
- Uses a dead-simple, JSON-based protocol.
- Stores entries as content-addressed blobs.
- Persists to disk by default.
npm install --global tcp-log-servertcp-log-server
Logs
The server uses pino logging. To improve console log output:
npm install --global pinotcp-log-server | tee server.log | pino
Environment
Configure tcp-log-server
with environment variables:
PORT
for TCPBLOBS
directory for entry JSON files, named by hash, ormemory
to store in memoryFILE
for the list of entries
Node.js
The package exports a factory function. Given a pino log, a file
path, an abstract-blob-store, and an EventEmitter
, it returns a TCP
connection handler function suitable for net.createServer(handler)
.
You may also provide a hash function and hash length.
Protocol
The server accepts TCP connections. It enables keep-alive on each socket. All messages are newline-delimited JSON objects. tcp-log-client provides a high-level interface.
Clients can send:
Read
On receipt, the server will begin sending up to read
log entries
with indices greater than or equal to from
, in ascending-index order.
(The lowest possible index is 1
.)
Each entry will be sent like:
Servers may report errors reading specific log entries:
If the server reaches the head of its log before sending read
entries, it will send:
Once the server has sent read
entries, it will report the index of
the head of its log:
Write
require('uuid').v4()
, with the uuid package, is an easy way to
generate id strings.
Once successfully appended to the log, the server will confirm the index of the newly appended entry.
If there is an error, the server will instead respond: