Node.js Quickstart
Use the Nebutra SDK in a Node.js backend or serverless function in under 5 minutes.
Prerequisites
- Node.js 22+
- A Nebutra account with an OPC license (free)
Step 1: Install the SDK
npm install @nebutra/sdkpnpm add @nebutra/sdkStep 2: Configure environment variables
NEBUTRA_API_KEY=nbk_live_xxxxxxxxxxxxxxxxxxxx
NEBUTRA_ORG_ID=org_xxxxxxxxxxxxxxxxxxxxStep 3: Initialize the client
import { createClient } from "@nebutra/sdk";
export const nebutra = createClient({
apiKey: process.env.NEBUTRA_API_KEY!,
orgId: process.env.NEBUTRA_ORG_ID!,
});Step 4: Verify a request token
If you're building an API that receives requests from Nebutra-authenticated users:
import { verifyToken } from "@nebutra/sdk/server";
export async function authMiddleware(req: Request) {
const token = req.headers.get("authorization")?.replace("Bearer ", "");
if (!token) throw new Error("Unauthorized");
const { userId, orgId, scopes } = await verifyToken(token, {
apiKey: process.env.NEBUTRA_API_KEY!,
});
return { userId, orgId, scopes };
}Step 5: Send a webhook event
import { nebutra } from "./lib/nebutra";
await nebutra.webhooks.send({
eventType: "invoice.paid",
payload: {
invoiceId: "inv_123",
amount: 9900, // cents
currency: "usd",
},
tenantId: "org_123",
});Step 6: Check a user's permission
import { nebutra } from "./lib/nebutra";
export async function deleteResource(userId: string, resourceId: string) {
const allowed = await nebutra.permissions.check({
userId,
action: "delete",
resource: "Project",
});
if (!allowed) {
throw new Error("Forbidden: missing project:delete scope");
}
// proceed with deletion
}Next steps
How is this guide?
Edit on GitHub
Last updated on