Back to Rxdb

Blazing-Fast Node Filesystem Storage

docs-src/docs/rx-storage-filesystem-node.md

17.1.02.1 KB
Original Source

import { PerformanceChart } from '@site/src/components/performance-chart'; import { PERFORMANCE_DATA_NODE, PERFORMANCE_METRICS } from '@site/src/components/performance-data'; import {PremiumBlock} from '@site/src/components/premium-block';

Filesystem Node RxStorage

The Filesystem Node RxStorage for RxDB is built on top of the Node.js Filesystem API. It stores data in plain JSON/txt files like any "normal" database does. It is a bit faster compared to the SQLite storage and its setup is less complex. Using the same database folder in parallel with multiple Node.js processes is supported when you set multiInstance: true while creating the RxDatabase.

Pros

<PremiumBlock /> <PerformanceChart title="Node/Native Storages" data={PERFORMANCE_DATA_NODE} metrics={PERFORMANCE_METRICS} />

Usage

ts
import {
    createRxDatabase
} from 'rxdb';
import {
    getRxStorageFilesystemNode
} from 'rxdb-premium/plugins/storage-filesystem-node';
import path from 'path';

const myRxDatabase = await createRxDatabase({
    name: 'exampledb',
    storage: getRxStorageFilesystemNode({
        basePath: path.join(__dirname, 'my-database-folder'),
        /**
         * Set inWorker=true if you use this RxStorage
         * together with the WebWorker plugin.
         */
        inWorker: false
    })
});
/* ... */

FAQ

<details> <summary>Does RxDB support single-file storage architectures in Node environments?</summary>

The native getRxStorageFilesystemNode adapter does not compile documents into a single monolithic file (like SQLite), but instead serializes and persists document data as distinct JSON/text files directly representing the database tree on the disk. For strict single-file architectures in Node.js, you must mount the specialized SQLite RxStorage plugin, which wraps the entire database state into a single portable .sqlite file efficiently using Node's native sqlite bindings.

</details>