Skip to main content

Quick Start

Whether you're using React or another JavaScript framework, this guide will help you get started with Lucix quickly and efficiently. If you're using React, you might find our React tutorial more relevant.

Install the Package

The first step is to add Lucix to your project. You can do this by running the following command in your project directory:

npm install @lucix/core

Or, if you're using Yarn:

yarn add @lucix/core

Import Lucix

Next, you'll need to import Lucix into your project. Add the following line to the top of your file:

import { lucix } from '@lucix/core'

You can import use-lucix instead of @lucix/core if you're using React, it also exports the lucix function as above.

Create a Ledger

Now, let's create your first ledger. You can do this with the following line of code:

const ledger = lucix("my-ledger")

The lucix function takes a single argument, the name of your ledger. It is safe to call this function multiple times with the same name. If the ledger already exists, it will be opened. If it doesn't exist, it will be created. The ledger connection is cached, so subsequent calls to lucix with the same name will return the same ledger object, making it safe to call lucix with every render.

Create and Read Documents

With your database set up, you can now create your first document. Here's how:

const ok = await ledger.put({ hello: "world" })

To read your first document, use the following code:

const doc = await ledger.get(ok.id)

Update Documents

Updating your document is just as easy. Here's how you can do it:

doc.hello = "universe"
const ok2 = await ledger.put(doc)

Query Documents

Finally, you can query all documents or query documents by a specific field. Here's how:

const docs = await ledger.allDocs()
const docs = await ledger.query('hello') // This will return documents with 'world' and 'universe'.

And that's it! You've successfully set up Lucix in your project. Happy coding!

See the React tutorial for a more complete example, or the ledger basics section for more details on how to use Lucix. Check out the GitHub Discussions for example apps and more help.


Lucix is an embedded database that brings seamless live sync to any infrastructure, allowing developers to build rich, local-first, collaborative apps. Ideal for finance, trading, point-of-sale, shopping cart, ERP, inventory, supply-chain, set-top box, call-center automation, AI agents, social software, pilot scheduling, event data recorder, IoT edge, distributed configuration, and more—anywhere trust and availability are critical.