The SurrealDB SDK for JavaScript
npm install @tai-kun/surrealdbA modular SurrealDB client working in major JavaScript runtimes.









> [!NOTE]
> The main branch is currently under development for SurrealDB v2.
> You can find the repository for SurrealDB v1 here.
https://tai-kun.github.io/surrealdb.js/getting-started/
``sh`
npm i @tai-kun/surrealdb
`ts
import { Surreal } from "@tai-kun/surrealdb";
const db = new Surreal();
await db.connect("
try {
await db.signin({ user: "root", pass: "root" });
await db.use("sample_namespace", "sample_database");
const results = await db.query<[number]>(/surql/ RETURN 42;);`
console.log(results); // [ 42 ]
} finally {
await db.close();
}
`ts
import { initSurreal } from "@tai-kun/surrealdb";
import Client from "@tai-kun/surrealdb/standard-client";
import HttpEngine from "@tai-kun/surrealdb/http-engine";
import JsonFormatter from "@tai-kun/surrealdb/json-formatter";
const { Surreal } = initSurreal({
Client: Client,
engines: {
http: config => new HttpEngine({
...config,
// fetch:
}),
https: "http",
},
formatter: new JsonFormatter(),
});
`
SurrealDB >=2.1.0
The repository for SurrealDB v1 is here.
| Env | Version |
| --- | --- |
| Node.js | 20.x,22.x *1 |1.x
| Deno | , 2.x *2 |1.x
| Bun | |>=104
| Chromium | *3 |>=100
| Firefox | *4 |>=15.4
| WebKit | *5 |
*1: Probably works with 18.x ^1.44.3
*2: Probably works with >=78
*3: Probably works with >=68
*4: Probably works with >=14
*5: Probably works with
| Env | Version |
| --- | --- |
| Node.js | 20.x,22.x,23.x |1.x
| Deno | ,2.x |1.x
| Bun | |>=104
| Chromium | |
| Env | Version |
| --- | --- |
| Node.js | 18.x |>=100
| Firefox | |>=15.4` |
| WebKit |