https://github.com/cbjs-dev/cbjs
A modern Couchbase SDK for Node.js and TypeScript.
https://github.com/cbjs-dev/cbjs
community couchbase http native typescript vitest
Last synced: 13 days ago
JSON representation
A modern Couchbase SDK for Node.js and TypeScript.
- Host: GitHub
- URL: https://github.com/cbjs-dev/cbjs
- Owner: cbjs-dev
- License: apache-2.0
- Created: 2024-01-06T23:42:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-06-04T13:58:13.000Z (17 days ago)
- Last Synced: 2026-06-04T14:06:51.380Z (17 days ago)
- Topics: community, couchbase, http, native, typescript, vitest
- Language: TypeScript
- Homepage: https://cbjs.dev
- Size: 16.2 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Notice: NOTICE
Awesome Lists containing this project
README
A modern Couchbase SDK for Node.js & TypeScript.
Documentation | Getting Started | Why Cbjs?
## Getting started
To get started with your new Couchbase Node.js SDK, uninstall the official library and install Cbjs :
```bash
npm uninstall couchbase
npm install @cbjsdev/cbjs
```
## Compatibility
Built on top of the official library, Cbjs is a drop-in replacement for the `couchbase` package.
The package that is specific to your platform is downloaded during the install process.
Cbjs is also full **ESM native**.
Cbjs is your new [Couchbase SDK for Node.js with TypeScript](https://cbjs.dev/guide/features.html#compatible-with-the-official-client).
## Exclusive Features
Cbjs has been created to deliver a better DX.
By making extensive usage of TypeScript, Cbjs is able to add some exclusive features.
### Inferred return type for KV operation
Because Cbjs knows your documents, the return type of KV operations is inferred from the parameters.

Read more about [couchbase document path autocomplete](https://cbjs.dev/guide/features.html#inferred-return-type).
### Chainable sub-document operations
Adopt a more elegant syntax by chaining sub-document operations.
```ts
const result = await collection.lookupIn('book::001')
.get('title')
.exists('lastModifiedBy')
.count('metadata.tags');
```
Read more about [chainable lookupIn](https://cbjs.dev/guide/services/kv.html#chainable-sub-doc-operations).
### Path autocomplete for sub-document operation
Because Cbjs knows your documents, autocompletion is offered when writing a document path.

### Improved types
Great efforts have been made to improve function signatures and types in general. Here is an example that uses _discriminated unions_ to offer a natural type guard :
```ts
const { content: [title] } = await collection.lookupIn(bookId).get('title');
// ^? LookupInResultEntry | LookupInResultEntry
if (title.error) {
throw new Error('Failed to retrieve the title.');
}
// Because of the discriminated union, the previous condition acts as a type guard.
// title: LookupInResultEntry
```
The same goes for callbacks and many more ! [Read more](https://cbjs.dev/guide/features.html#discriminated-unions).
### Better Stack Trace
Without `cbjs` :
```
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
```
With `cbjs` :
```
DocumentNotFoundError: document not found
at errorFromCpp (/yourProject/node_modules/@cbjsdev/cbjs/src/bindingutilities.ts:787:14)
at Collection.remove (/yourProject/node_modules/@cbjsdev/cbjs/src/collection.ts:1417:19)
at remove (/yourProject/something.ts:31:3)
```
### Support for cloud lambdas
Access to the file system via `node:fs` is sometimes unavailable on cloud lambdas like Cloudflare Workers.
Because Cbjs doesn't use it to load the driver binary, it works fine on all cloud lambdas providers.
## License
All the packages are released under the Apache 2.0 license.