Skip to main content

Getting Started

Before you can use this SDK for JavaScript regardless of your environment, you need to install and import it into your project. This guide will walk you through the process of installing and importing the SDK into your project.

Install the SDK

First, install the SurrealDB SDK using your favorite package manager:

npm install --save surrealdb.js

Import the SDK to your project

After installing, you can then import the SDK into your project. Depending on your setup and environment, we supported multiple options.

Note: It is recommended to import this in a utility file or a file that is shared across your application.

CommonJS
const { SurrealDB } = require('surrealdb.js');
ES6
import { SurrealDB } from 'surrealdb.js';

In a deno runtime, you can import the SDK using the following syntax:

Deno
import Surreal from "https://deno.land/x/surrealdb/mod.ts";

To set the version in the URL, you can use the following syntax:

Deno
import Surreal from "https://deno.land/x/surrealdb@1.0.0/mod.ts";

Importing via a CDN is also supported:

CDN
import Surreal from "https://unpkg.com/surrealdb.js";
// or
import Surreal from "https://cdn.jsdelivr.net/npm/surrealdb.js";

Initialize the SDK

The SDK's initialization may vary depending on your environment.