@sampathkumara/realtime-sync-server
v1.0.25
Published
Real-time data synchronization server with LokiJS and Socket.IO. Self-hosted, offline-first sync for Node.js applications.
Maintainers
Readme
Sync Server
High-performance, real-time data synchronization server built with LokiJS, Socket.IO, and Express. This server is designed for applications that require instant data updates and efficient client-server communication.
Key Features
- Real-time Sync: Uses Socket.IO to push changes to clients instantly.
- RESTful API: Provides a complete REST API for standard HTTP interactions.
- Efficient In-Memory Database: Powered by LokiJS for extremely fast data access.
- Delta Synchronization: Only sends changes since the client's last sync time, saving bandwidth.
- Bulk Operations: Optimized endpoints for high-performance bulk inserts, updates, and deletes.
- Change Consolidation: In-memory consolidation of changes to reduce database I/O and ensure only the net change is logged.
- Configurable: Easily configure the server, logging, and database settings using a
.envfile. - Structured Logging: Uses Winston for structured, leveled logging.
- Compression: Enables per-message deflate compression to reduce bandwidth.
Getting Started
1. Installation
npm install2. Configuration
Create a .env file in the root of the project. You can copy the .env.example file to get started:
cp .env.example .envModify the .env file to customize your settings:
# Server Configuration
PORT=3000
CORS_ORIGIN=*
# Database Configuration
DB_PATH=./data/sync.db
DB_AUTOSAVE=true
DB_AUTOSAVE_INTERVAL=5000
# Logging Configuration
LOG_LEVEL=info
LOG_ENABLED=true
LOG_FILE=./logs/sync-server.log
LOG_ERROR_FILE=./logs/sync-server-error.log
# Bulk Operation Configuration
DEFAULT_BATCH_SIZE=500
BATCH_DELAY_MS=5
# Compression Configuration
COMPRESSION_ENABLED=true
# Socket.IO Transports (comma-separated: websocket,polling)
TRANSPORTS=websocket,polling3. Running the Server
import { SyncServer } from './src/SyncServer';
// Default server
const server = new SyncServer();
server.start();
// Server with a separate .env file
const server2 = new SyncServer({
envFilePath: './.env.server2',
});
server2.start();
// Server with custom parameters
const server3 = new SyncServer({
port: 3003,
dbPath: './data/server3.db',
transports: ['polling'], // Force polling for this instance
});
server3.start();API Documentation
For a detailed API reference, see API_DOCUMENTATION.md.
Development
# Install dependencies
npm install
# Run development server with hot-reloading
npm run dev
# Build for production
npm run build
# Start production server
npm startLicense
MIT
