Backend JSRuntime GuidesNode.js
Node.js Overview
Use @wacht/backend in long-running Node.js services, jobs, and internal APIs.
Recommended shape
Initialize once at process startup, then call typed API groups from route handlers and jobs.
import { initClient, users } from '@wacht/backend';
initClient({
apiKey: process.env.WACHT_API_KEY!,
baseUrl: process.env.WACHT_BACKEND_API_URL,
timeout: 30_000,
});
export async function listUsersForAdmin() {
return users.listUsers({ limit: 50, offset: 0 });
}Service-level patterns
- Keep one initialized client per process.
- Use per-request correlation headers only when needed by creating a custom
WachtClient. - Treat backend API key as a privileged secret.
import { WachtClient } from '@wacht/backend';
export function makeRequestScopedClient(requestId: string) {
return new WachtClient({
apiKey: process.env.WACHT_API_KEY!,
headers: { 'x-request-id': requestId },
});
}