Quick Start
Setup Server
Create new project:
- npm
- yarn
- pnpm
mkdir myserver && cd myserver
npm init
npm install @socketdb/server
mkdir myserver && cd myserver
yarn init
yarn add @socketdb/server
mkdir myserver && cd myserver
pnpm init
pnpm add @socketdb/server
Create index.js
file with:
import { SocketDBServer } from '@socketdb/server';
SocketDBServer().listen(8080);
Run it with node index.js
.
Setup Client
- npm
- yarn
- pnpm
npm install @socketdb/client
yarn add @socketdb/client
pnpm add @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.