{"library":"rxdb-server","title":"RxDB Server","description":"RxDB Server is a plugin for the RxDB (Reactive Database) ecosystem, enabling server-side capabilities for RxDB databases. It allows users to spawn a server on top of an RxDB instance, providing various endpoints such as CRUD REST APIs and real-time replication endpoints. This facilitates data synchronization between client devices and the server, supporting offline-first architectures and real-time data updates. The package is designed for Node.js, Deno, Bun, or Electron's main process and can operate as a standalone server or integrate with existing HTTP frameworks like Express. Currently at version 17.1.0, it generally follows the release cadence of the main RxDB library. A key differentiator is its Server Side Public License (SSPL), similar to MongoDB's, which aims to prevent large cloud vendors from monetizing the software without contributing back. The plugin is maintained separately from the core RxDB due to its specific dependencies and licensing model.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rxdb-server"],"cli":null},"imports":["import { createRxServer } from 'rxdb-server/plugins/server';","import { RxServerAdapterExpress } from 'rxdb-server/plugins/adapter-express';","const myServer = await createRxServer(...);\nmyServer.addReplicationEndpoint(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createRxDatabase, addRxPlugin } from 'rxdb';\nimport { getRxStorageMemory } from 'rxdb/plugins/storage-memory';\nimport { RxDBDevModePlugin } from 'rxdb/plugins/dev-mode';\nimport { createRxServer } from 'rxdb-server/plugins/server';\nimport { RxServerAdapterExpress } from 'rxdb-server/plugins/adapter-express';\n\nconst runServer = async () => {\n  // Enable dev mode for helpful warnings in development\n  addRxPlugin(RxDBDevModePlugin);\n\n  // Define a simple schema for our data\n  const mySchema = {\n    version: 0,\n    primaryKey: 'id',\n    type: 'object',\n    properties: {\n      id: { type: 'string', maxLength: 100 },\n      name: { type: 'string', maxLength: 100 },\n      age: { type: 'number' }\n    },\n    required: ['id', 'name']\n  };\n\n  // Create a RxDB database in memory for demonstration\n  const db = await createRxDatabase({\n    name: 'heroesdb',\n    storage: getRxStorageMemory()\n  });\n\n  // Add a collection\n  const heroesCollection = await db.addCollections({\n    heroes: { schema: mySchema }\n  });\n\n  // Insert some initial data\n  await heroesCollection.heroes.insert({\n    id: 'hero1',\n    name: 'SuperMan',\n    age: 40\n  });\n  console.log('Initial data inserted into RxDB.');\n\n  // Create the RxDB Server\n  const rxdbServer = await createRxServer({\n    database: db,\n    adapter: RxServerAdapterExpress,\n    port: 3000,\n    cors: true\n  });\n\n  // Add a replication endpoint for the 'heroes' collection\n  await rxdbServer.addReplicationEndpoint({\n    name: 'heroes-replication',\n    collection: heroesCollection.heroes\n  });\n\n  // Add a REST endpoint for basic CRUD operations\n  await rxdbServer.addRESTEndpoint({\n    name: 'heroes-rest',\n    collection: heroesCollection.heroes\n  });\n\n  // Start the server\n  await rxdbServer.start();\n  console.log('RxDB Server started on http://localhost:3000');\n  console.log('Replication endpoint: http://localhost:3000/heroes-replication/0');\n  console.log('REST endpoint (query): POST http://localhost:3000/heroes-rest/query');\n};\n\nrunServer().catch(err => console.error('Error starting server:', err));","lang":"typescript","description":"This quickstart demonstrates setting up an in-memory RxDB, creating an RxDB server with Express adapter, and exposing replication and REST endpoints.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}