Examples
Each example is short and focused on one pattern for building applications with Holster.
Running the examples
Every example can be run in Node's REPL, the interactive prompt you get by typing node on its own. In an empty folder, install Holster and start the REPL:
npm install @mblaney/holster
nodeThen paste these lines at the prompt:
const {default: Holster} = await import("@mblaney/holster/src/holster.js")
const holster = Holster({port: 8765})The REPL can't use import statements, so the first line uses import() instead, and await works at the prompt without a function around it. Passing a port makes this instance a relay, which stores data in a radata folder, so the examples work without connecting to anything else.
You can paste each block of an example in one go, since the REPL waits for each await to finish before running the next line. A few things to know:
Lines that use a callback, such as
user.auth(..., console.log), don't make the REPL wait. They print their result when they finish, so wait for it before pasting the next block.Declaring the same
consttwice is an error in the REPL. To start again, type.exit, then delete theradatafolder if you want to clear the stored data too.Type
.exitor press Ctrl+D twice to leave.
The examples
Private notes: encrypt what a user writes, while keeping what the app needs readable.
Live lists: show a list that updates as notes are added, edited and deleted.
Data shared by the host: let a server's host account send private values to each user.