Home / Companies / SurrealDB / Blog / Post Details
Content Deep Dive

Connecting your Next.js app on Cloudflare to SurrealDB Earth

Blog post from SurrealDB

Post Details
Company
Date Published
Author
Tobie Morgan Hitchcock
Word Count
1,582
Company Posts That Month
8
Language
English
Hacker News Points
-
Post removed?
No
Summary

SurrealDB Earth can be connected to a Next.js application running on Cloudflare Workers by creating a new SurrealDB JavaScript SDK client for each request, using it through a shared helper, and closing it before the request ends. The setup uses an Earth instance endpoint, a dedicated database user rather than root credentials, and Cloudflare Worker bindings for the URL, namespace, database, username, and password or token, accessed through OpenNext’s Cloudflare context. Server Components, route handlers, and server actions can reuse the helper to read and write records, while pages that require fresh database reads should be configured as dynamic. HTTP is recommended for simple, low-query request handlers, while WebSockets are necessary for interactive transactions and live queries and may be more efficient for many queries within one request. Because password-based authentication incurs hashing overhead on every Worker request, stored tokens can improve performance where appropriate. The guidance also distinguishes application-level credentials from end-user access, recommending record access tokens and table permissions to restrict users to their own data. Unlike long-running Node.js servers, Workers should not use module-level shared clients, must read configuration from bindings rather than environment variables, and should have schemas defined before application requests begin.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
AI Agents 1 4,018 791 204 -43%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.