@couchbase/lite-js

中文文档
1.0.3发布于 2026/10/16See LICENSE.txtTypeScriptESM + CJS近 30 天下载 7159

This is the JavaScript (really TypeScript) implementation of Couchbase Lite.

原始使用文档
文档目录11 节
  1. 1. Getting Started / Documentation
  2. Using It In Your Own Projects
  3. 2. Source Code
  4. 3. Building It Yourself
  5. Dependencies
  6. Building
  7. Running Tests
  8. Integration Tests aka the TDK
  9. 4. Running The Examples
  10. …in a web browser
  11. …from the command line

Couchbase Lite for JavaScript

This is the JavaScript (really TypeScript) implementation of Couchbase Lite.

It's intended for use in web browsers.

Server and CLI environments like Node.js, Deno and Bun are not officially supported, because they lack a proper implementation of the IndexedDB API. You can use CBL-JS in those environments with the help of the fake-indexeddb package, but it's not very useful because databases are not persisted to disk.

This ReadMe last updated Nov 12 2025.

1. Getting Started / Documentation

The wiki has some documents introducing the API, and describing differences from other Couchbase Lite platforms.

For an example of using the API in a web page, see examples/browser.ts. If you want to run that example yourself, see "Kicking The Tires".

Using It In Your Own Projects

Install the NPM package "@couchbase/lite-js".

Install analytics (Reo.dev)

This package depends on reo-census, which sends a one-time install event to Reo.dev from its postinstall script. The event includes the package name and version, OS and Node.js details, the install timestamp and directory, your git user name, the domain of your git email address (not the full address), and CI environment info. Nothing is sent at runtime; CBL-JS itself makes no analytics calls.

To opt out, set PACKAGE_TRACKER_ANALYTICS=false when installing:

PACKAGE_TRACKER_ANALYTICS=false npm install @couchbase/lite-js

Installs that don't run dependency install scripts send nothing: npm install --ignore-scripts, Bun, pnpm 10+ and Yarn 4 (the last three skip dependency postinstall scripts by default).

2. Source Code

Code is in the src directory. The public API is declared in src/couchbase-lite.ts, which just re-exports public symbols.

Subdirectories are:

  • blip: The BLIP RPC protocol, used by the replicator
  • blob: Blob/attachment classes and support code
  • database: Database, Collection and document implementation; plus the public Replicator class
  • query: Query implementation
  • replicator: Replicator implementation (but not its public API)
  • util: Internal utilities

Tests are intermingled in the source directories, in files named *.test.ts.

3. Building It Yourself

Dependencies

For development you'll need to install either Bun, or node.js and npm. These directions assume bun; if you use node+npm, substitute npm for bun in command lines.

Package dependencies (will be installed by Bun):

  • General:
  • BLIP RPC:
  • Database:
    • dexie -- High-level wrapper for IndexedDB.
    • fake-indexeddb -- In-memory IndexedDB implementation (not needed in browsers)
    • sha.js -- SHA-1 digests (used instead of JS crypto because it's synchronous.)
    • buffer -- Required to use sha.js in a browser.
  • Query:
    • ohm-js -- Parser library, used for N1QL/SQL++.
    • date-fns -- For the N1QL date/time functions
    • regexp.escape -- Escapes regular expression strings. Used in implementation of LIKE.

Building

To compile the TypeScript code in ./src into minified JavaScript files in ./dist:

  1. bun install (first time only)
  2. bun run build

Running Tests

Tests are in files named *.test.ts. They are run by vitest.

  • To run the base (non-replicator) tests: bun run test
  • To run the base tests in a browser: bun run test:browser
  • To run the base tests with database encryption: bun run test:encrypted
  • To run the replicator tests: bun run test:replicator or bun run test:replicator-encrypted (requires configuring Sync Gateway first; see notes in src/database/replicator.test.ts)
  • To run the N1QL conformance tests: bun run test:n1ql or bun run test:niql-encrypted (requires downloading about 24MB of test data first; see directions in src/query/N1QLTestSuite.test.ts)

Integration Tests aka the TDK

Note: The TDK is internal to Couchbase, not public.

Integration & system tests of all Couchbase Lite platforms are performed by the Test Development Kit (TDK). The glue code that integrates CBL-JS is in the servers/javascript directory.

4. Running The Examples

…in a web browser

See the wiki page "Kicking the Tires".

…from the command line

We have a test of replication in a server environment (Bun or node.js). Since IndexedDB is not available, it uses the "fake-indexeddb" package; this database is ephemeral, since it's only for testing purposes.

To run, first read the instructions at the top of examples/sync_collections_node.ts and set up your server (Sync Gateway or Edge Server).

Then run bun run examples/sync_collections_node.ts

版本与发布记录

@couchbase/lite-js 共发布 4 个版本,首次发布于 2025/11/12;过去 12 个月发布了 4 个版本。

版本发布日期距今
1.0.3latest2026/10/1625 天前
1.0.22026/09/052 个月前
1.0.12026/05/285 个月前
1.0.02025/11/1211 个月前

关于 @couchbase/lite-js 的常见问题

@couchbase/lite-js 是什么?

This is the JavaScript (really TypeScript) implementation of Couchbase Lite.

如何安装 @couchbase/lite-js?

在项目目录运行 npm install @couchbase/lite-js,或使用 pnpm add / yarn add / bun add。

@couchbase/lite-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@couchbase/lite-js 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@couchbase/lite-js 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@couchbase/lite-js 可以商用吗?

@couchbase/lite-js 使用 See LICENSE.txt 许可。声明的许可为 See LICENSE.txt,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@couchbase/lite-js 的下载量有多少?

根据 npm 官方下载统计,@couchbase/lite-js 在 2026/10/11 – 2026/11/09 这 30 天内被下载 7,159 次,日均约 239 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@couchbase/lite-js 还在维护吗?

最新版本 1.0.3 发布于 2026/10/16(25 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2025/11/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。