The only change you need is the databaseURL in your Firebase config. Here’s a typical config object — the highlighted line is the only thing you change:
var firebaseConfig = {
apiKey: "API_KEY",
authDomain: "PROJECT_ID.firebaseapp.com",
// Change this from https://PROJECT_ID.firebaseio.com
databaseURL: "https://your-lark-project-id.larkdb.net",
projectId: "PROJECT_ID",
storageBucket: "PROJECT_ID.firebasestorage.app",
messagingSenderId: "SENDER_ID",
appId: "APP_ID",
measurementId: "G-MEASUREMENT_ID",
};
That’s it. One line. The rest of your code stays exactly the same — every ref(), on(), set(), and update() call works without modification.
Firebase JS SDK v8
import firebase from 'firebase/app';
import 'firebase/database';
firebase.initializeApp({
databaseURL: 'https://your-lark-project-id.larkdb.net'
});
const db = firebase.database();
Firebase JS SDK v9 (modular)
import { initializeApp } from 'firebase/app';
import { getDatabase, ref, set } from 'firebase/database';
const app = initializeApp({
databaseURL: 'https://your-lark-project-id.larkdb.net'
});
const db = getDatabase(app);
Project settings
Before connecting, make sure your Lark project is configured correctly:
- Allow Legacy Firebase must be enabled in your Lark project settings. This turns on the Firebase wire protocol.
- If your Firebase app stores many independent data silos under path prefixes (game rooms, workspaces, etc.), see Database routing for options on splitting them into separate Lark databases.
You can test Lark with a percentage of your traffic first. Send 5% of connections to Lark and keep 95% on Firebase. If anything goes wrong, switch back — one URL change.