December 1, 2020

HarperDB and WebSockets

Welcome to Community Posts
Click below to read the full article.
Summary of What to Expect
Table of Contents

This demo will walk you through the creation of a Node.js project powered by WebSockets and HarperDB. The application will be a data entry CLI with an additional display script.

  1. Ensure you have Node.js v14 and Docker Desktop installed.
  2. Create a new folder for the project and set it as the current working directory.
  3. Create a docker-compose.yml file with the provided configuration to set up HarperDB using Docker.
  4. Initialize a new npm project and install the required dependencies.
  5. Create three project files: init.js, data-entry.js, and data-display.js.
  6. Launch HarperDB using Docker with docker-compose up.
  7. init.js: Contains setup operations for the schema and table in HarperDB. It uses undici, a fast HTTP client, to perform the operations.
  8. data-entry.js: Allows data entry into the HarperDB table through a CLI. It uses HarperDBWebSocketClient to insert records over WebSockets.
  9. data-display.js: Subscribes to the HarperDB table and logs every new record inserted using WebSocket.