Node.js
Use the Node entrypoint for CLIs, workers, background jobs, and long-running services. It includes env config helpers and lifecycle hooks that keep resource cleanup predictable.
Why use ffdb-client/node
- Name
Env config utilities- Description
loadEnvConfig()maps Node env values into a full FFDB config object.
- Name
Lifecycle safety- Description
createNodeLifecycle()wires process shutdown signals to clientdestroy().
- Name
Same core client API- Description
You still get
db,sql,auth,sync, andgetAccessfrom one client instance.
Node entrypoint surface
import { createClient, createNodeLifecycle, loadEnvConfig } from 'ffdb-client/node'
Key helpers:
type NodeHelpers = {
loadEnvConfig: (options?: { path?: string; quiet?: boolean }) => FFDB_Config
createNodeLifecycle: () => LifecycleHooks
}
End-to-end service pattern
import { createClient, createNodeLifecycle, loadEnvConfig } from 'ffdb-client/node'
import type { Database } from './ffdb.types'
const config = loadEnvConfig({ path: '.env', quiet: true })
const { db, sync, destroy } = await createClient<Database>({
config,
lifecycle: createNodeLifecycle(),
})
const users = await db.selectFrom('user').select(['id', 'email']).execute()
console.log(users)
await sync?.run()
await destroy()
Recommended env keys for Node
API_URL="https://your-app.ffdb.forever-frameworks.com"
ORIGIN="https://your-service.example.com"
FFDB_AUTH_TOKEN="your-admin-token"
FFDB_API_KEY="optional-direct-api-key"
RETRY_ATTEMPTS="2"
HEALTH_PROBE_INTERVAL_MS="1000"
LOG_LEVEL="info"
LOG_ENABLED="false"
Lifecycle behavior
createNodeLifecycle() registers cleanup on common process events (SIGINT, SIGTERM, beforeExit) so FFDB resources are released during shutdown.
Why this matters:
- Long-running processes avoid leaking timers and listeners.
- Repeated test/service boots stay clean without accumulating handlers.
- Shutdown behavior is consistent whether exit is manual or orchestrated.
Practical guidance
- Use
loadEnvConfig()early and pass the resulting config explicitly. - Use
createNodeLifecycle()by default for services and workers. - Call
destroy()in short-lived scripts for deterministic teardown. - Keep admin credentials in trusted Node environments only.