Triplit in Node.js
Node is the default runtime for the Triplit server. 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
SQLite
SQLite is the default storage option for the Triplit server. 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.
LMDB
LMDB (opens in a new tab) is a fast, memory-mapped database that is designed for high performance.
Example
import { createServer } from '@triplit/server';
const port = +(process.env.PORT || 8080);
const startServer = await createServer({
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();
});
});