Installing Couchbase Lite JavaScript
Description — How to install Couchbase Lite JavaScript
Abstract — Getting you up and running quickly with Couchbase Lite JavaScript
Introduction
Couchbase Lite JavaScript is distributed as an npm package and supports development in both JavaScript and TypeScript.
Installation
Add Couchbase Lite JavaScript to your web application project using npm:
npm install @couchbase/lite-js
Then import Couchbase Lite in your JavaScript/TypeScript code:
import { Database, Replicator } from '@couchbase/lite-js';
That’s it! You’re all set to begin developing offline-first web applications.
Verify Installation
After installing, verify that Couchbase Lite is correctly installed.
Verify Import
Create a simple test file:
// test.js
import { Database, Version } from '@couchbase/lite-js';
console.log('Couchbase Lite version:', Version);
Test Basic Functionality
Test creating a database:
import { Database } from '@couchbase/lite-js';
async function test() {
try {
const db = await Database.open('test-db', {
name: 'test-db',
version: 1,
collections: {
items: {}
}
});
console.log('✓ Database created successfully');
await db.close();
console.log('✓ Database closed successfully');
// Clean up
await Database.deleteDatabase('test-db');
console.log('✓ Database deleted successfully');
} catch (error) {
console.error('✗ Installation test failed:', error);
}
}
test();