Node.js engine
The @surrealdb/node package is a plugin for the JavaScript SDK that allows you to run SurrealDB as an embedded database within a Node.js server-side environment. It supports in-memory databases and persistent storage via RocksDB and SurrealKV, and is also compatible with Bun and Deno.
Important
Installing the Node.js engine
Before installing the Node.js engine, you need the core JavaScript SDK installed. Then add the @surrealdb/node package.
Registering the engine
Import createNodeEngines from @surrealdb/node and spread it into the engines option alongside createRemoteEngines from the core SDK. This registers the embedded protocols while keeping remote connections available.
Supported connection protocols
Once the Node.js engine is registered, you can connect to SurrealDB using the embedded protocols.
| Protocol | Description |
|---|---|
mem:// | In-memory database (data is lost when the process exits) |
rocksdb:// | Persistent database backed by RocksDB |
surrealkv:// | Persistent database backed by SurrealKV |
To enable versioned storage for temporal queries, append ?versioned=true to the connection string.
Remote protocols (ws://, wss://, http://, https://) remain available when createRemoteEngines() is also registered.
Bun and Deno compatibility
The @surrealdb/node engine is compatible with Bun and Deno in addition to Node.js. The installation and usage are the same across all three runtimes.
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 and to avoid console warnings.
Learn more
Node.js engine reference for additional engine configuration
Connecting to SurrealDB for connection options and reconnection behavior