The JavaScript SDK supports running SurrealDB as an embedded database through two engine plugins. Choose the one that matches your environment:
| Engine | Package | Environment | Storage options |
|---|---|---|---|
| WebAssembly | @surrealdb/wasm | Browsers | mem://, indxdb:// |
| Node.js | @surrealdb/node | Node.js, Bun, Deno | mem://, rocksdb://, surrealkv:// |
Both plugins work with ES modules (import), not CommonJS (require).
WebAssembly engine (browser)
The @surrealdb/wasm package runs SurrealDB inside a browser environment. It supports in-memory databases and persistent storage via IndexedDB, and can optionally run inside a Web Worker to keep the main thread responsive.
Installation
Registering the engine
Running in a Web Worker
Offload database operations from the main thread to keep your interface responsive:
Bundler configuration
If you are using a bundler like Vite, you may need to exclude the WASM package from dependency optimisation and enable top-level await:
Node.js engine (server)
The @surrealdb/node package runs SurrealDB within Node.js, Bun, or Deno. It supports in-memory databases and persistent storage via RocksDB and SurrealKV.
Installation
Registering the engine
To enable versioned storage for temporal queries, append ?versioned=true to the connection string:
Closing the connection
When using the Node.js engine, you must close the connection with .close() when you are done to ensure the database is properly shut down:
Learn more
Connecting to SurrealDB for connection options and reconnection behaviour