Skip to main content

Quick Start

Setup Server

Create new project:

mkdir myserver && cd myserver
npm init
npm install @socketdb/server

Create index.js file with:

import { SocketDBServer } from '@socketdb/server';

SocketDBServer().listen(8080);

Run it with node index.js.

Setup Client

npm install @socketdb/client

To use SocketDB, you need to setup your frontend with a bundler (like rollup) that bundles your node_modules.

Then you can just import the client:

import { SocketDBClient } from '@socketdb/client';

Start client & connect to server

Then, in your frontend javascript, you can connect to the server like this:

const db = SocketDBClient({ url: 'ws://localhost:8080' });

db.get('some').get('path').on(console.log);
db.get('some').set({ path: 'Hello World' });
Typescript

SocketDB has full typescript support. I recommend using typescript with SocketDB to get the benefits of code completion and type checking. For example you can add a Data Schema.