Framework Quick Start Guides
Find the recommended integration path for your specific framework.
Express
javascript
import express from 'express'
import notaify, { notaifyMiddleware } from '@notaify/node'
notaify.init({
apiKeyId: process.env.NOTAIFY_API_KEY_ID,
apiKey: process.env.NOTAIFY_API_KEY,
})
const app = express()
app.get('/', async (req, res) => {
res.send('Hello World')
})
app.use(notaifyMiddleware())
app.listen(3000)Fastify
javascript
import Fastify from 'fastify'
import notaify, { notaifyMiddleware } from '@notaify/node'
notaify.init({
apiKeyId: process.env.NOTAIFY_API_KEY_ID,
apiKey: process.env.NOTAIFY_API_KEY,
})
const fastify = Fastify()
// Set notaify as the global error handler
fastify.setErrorHandler(notaifyMiddleware({ framework: 'fastify' }))
fastify.get('/', async () => ({ hello: 'world' }))
fastify.listen({ port: 3000 })Next.js (App Router)
Use the notaifyHandler to wrap individual API route handlers.
typescript
// app/api/users/route.ts
import notaify, { notaifyHandler } from '@notaify/node'
// Best to call init in a shared utility file, but shown here for clarity
notaify.init({
apiKeyId: process.env.NOTAIFY_API_KEY_ID,
apiKey: process.env.NOTAIFY_API_KEY,
})
export const GET = notaifyHandler(async (req) => {
const users = await db.getUsers()
return Response.json(users)
})Important Note for Next.js
Notaify only works server-side (Node.js runtimes). Never use it in client components or leak your credentials into the browser.
NestJS
Integrate Notaify in a global Exception Filter to capture unhandled exceptions across the application.
typescript
// main.ts
import notaify from '@notaify/node'
notaify.init({
apiKeyId: process.env.NOTAIFY_API_KEY_ID,
apiKey: process.env.NOTAIFY_API_KEY,
})
// notaify-exception.filter.ts
import { Catch, ArgumentsHost } from '@nestjs/common'
import notaify from '@notaify/node'
@Catch()
export class NotaifyExceptionFilter {
async catch(exception: unknown, host: ArgumentsHost) {
// Capture the error using notaify.capture
await notaify.capture(exception as Error)
// Provide standard nestjs response handling...
}
}