Integrations / Frameworks / Express
Add business event alerts to Express route handlers or middleware. Works with any Express middleware stack and any database.
npm install logit express
// src/lib/logit.ts
import { init } from "logit";
export const logit = init({ token: process.env.LOGIT_API_KEY! });
import express from "express";
import { logit } from "./lib/logit";
const app = express();
app.use(express.json());
app.post("/signup", async (req, res) => {
const { email, plan } = req.body as { email: string; plan: string };
// ... persist user
await logit.now("signups", {
event: "New user signed up",
description: `${email} joined on ${plan}`,
icon: "๐ค",
notify: true,
tags: { plan },
metadata: { email, ip: req.ip },
});
res.json({ ok: true });
});
import type { Request, Response, NextFunction } from "express";
app.use(async (err: Error, req: Request, res: Response, _next: NextFunction) => {
await logit.now("errors", {
event: "Unhandled error",
description: err.message,
icon: "โ",
notify: true,
tags: { path: req.path, method: req.method },
metadata: { stack: err.stack },
});
res.status(500).json({ error: "Internal Server Error" });
});
# .env
LOGIT_API_KEY=lk_live_xxxxxxxxxxxxxxxx
Ready to connect Express?
7-day free trial. No credit card required.