#Can reactive convex client be used from within Convex Node action?
4 messages · Page 1 of 1 (latest)
Hi @upbeat geyser. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The knowledge sources do not explicitly address using the reactive ConvexClient from within a Convex action (Node.js runtime). However, based on what the knowledge sources do say, here is what can be stated:
What the knowledge sources confirm
The reactive ConvexClient (which supports WebSocket-based subscriptions via onUpdate) is described as suitable for Node.js environments and long-running servers: [Convex JavaScript Clients]
"The reactive Convex Client allows web applications and long-running Node.js servers to subscribe to updates on Convex queries."
Example usage in Node.js:
import { ConvexClient } from "convex/browser";
import { api } from "../convex/_generated/api";
const client = new ConvexClient(process.env.CONVEX_URL!);
client.onUpdate(api.messages.listAll, {}, (messages) =>
console.log(messages.map((msg) => msg.body)),
);
Important caveats
-
The knowledge sources do not explicitly confirm or deny whether instantiating a
ConvexClientinside a Convex action (running on Convex's infrastructure) is a supported or recommended pattern. -
Convex actions are described as able to run for up to 10 minutes and can call external services, but the knowledge sources do not discuss using a
ConvexClientsubscription loop from within an action to wait for data changes. [Why calling an action from a client is an anti-pattern?]
- The typical recommended pattern for reacting to data changes in Convex is to use
useQueryon the client side, or to schedule follow-up mutations/actions viactx.scheduleron the server side — not to poll or subscribe from within an action. [Action Triggers from Convex Queries]