Runtime support
Bun

Triplit in Bun

Triplit can run natively in Bun and persist data using Bun's native bun:sqlite package. Triplit provides an example implementation (opens in a new tab) and a docker image (opens in a new tab). Read more about self-hosting Triplit in the self-hosting documentation.

Supported storage options

bun:sqlite

bun:sqlite (opens in a new tab) is Bun's SQLite3 driver. It stores all data in a single SQLite database file. This is the recommended storage option for most use cases, as it is fast and easy to set up.

Dev server

You can run the Triplit development server in Bun with the following command:

bunx --bun triplit dev

You can add the -s sqlite flag to use bun:sqlite as the storage option.

Example

import { createBunServer } from '@triplit/server/bun';
 
const port = +(process.env.PORT || 8080);
 
const startServer = await createBunServer({
  storage: 'sqlite',
  verboseLogs: !!process.env.VERBOSE_LOGS,
  jwtSecret: process.env.JWT_SECRET!,
  projectId: process.env.PROJECT_ID,
  externalJwtSecret: process.env.EXTERNAL_JWT_SECRET,
  maxPayloadMb: process.env.MAX_BODY_SIZE,
});
 
const dbServer = startServer(port);
 
console.log('running on port', port);
process.on('SIGINT', function () {
  dbServer.close(() => {
    console.log('Shutting down server... ');
    process.exit();
  });
});