All recipes
Fastify
CodePluginNode.js
The plugin initializes the SDK during registration and starts shutdown from the close hook. For a controlled shutdown, explicitly await the SDK before closing your server.
SDK access required
Node.js and browser packages are not on public npm yet. Contact us for access before following the installation steps. Check the SDK reference for your runtime and review what the SDK sends.
1. Install
Bash
npm install @checkupstream/sdk2. Register the plugin
server.ts
import Fastify from "fastify";
import { checkUpstreamPlugin } from "@checkupstream/sdk/integrations/fastify";
const sdkKey = process.env.CHECKUPSTREAM_SDK_KEY;
if (!sdkKey) throw new Error("Set CHECKUPSTREAM_SDK_KEY before starting the app");
const app = Fastify();
await app.register(checkUpstreamPlugin, {
sdkKey,
});
app.get("/api/users", async () => {
const response = await fetch("https://api.github.com/zen");
return { message: await response.text() };
});
await app.listen({ port: 3000 });Tip
The close hook starts SDK shutdown without awaiting it. In your application shutdown handler, await checkupstream.shutdown() before app.close() and process exit if the final batch must finish.
Related
Continue your setup
Check runtime availability and credentials before deploying an integration.