JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q35940F
  • License MIT

serve an append-only log over TCP

Package Exports

  • tcp-log-server

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tcp-log-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Serve an append-only log over TCP.

npm install --global tcp-log-server
tcp-log-server

Logs

The server uses pino logging. To improve console log output:

npm install --global pino
tcp-log-server | tee server.log | pino

Environment

Configure tcp-log-server with environment variables:

  • PORT for TCP
  • BLOBS directory for entry JSON files, named by hash
  • LEVELDB directory for LevelDB data files

Node.js

The package exports a factory function. Given a pino log, a LevelUP instance, an abstract-blob-store, and an EventEmitter, it returns a TCP connection handler function suitable for net.createServer(handler).

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

{"from":0}

On receipt, the server will begin sending log entries with indices greater than or equal to from. Each entry will be sent like:

{"index":"1","entry":{"some":"entry"}}

The server will send:

{"current":true}

once it has sent all entries in the log as of the time the read message was received.

Write

{"id":"some-id","entry":{"arbitrary":"data"}}

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.

{"id":"some-id","index":44}

The server will not echo the new entry back to the client that writes it.

If there is an error, the server will instead respond:

{"id":"some-id-string","error":"error-string"}