Guides / Platforms & Tools

Business Event Logging for Node.js Apps

3 min read·Platforms & Tools

Install

bash
npm install logit
# or
pnpm add logit
# or
yarn add logit

Initialize once, reuse everywhere

ts
// lib/logit.ts
import { init } from "logit";

export const logit = init({
  token: process.env.LOGIT_API_KEY!,
});

Create one instance at startup. The client is stateless and safe to share across requests.

The four events worth logging

ts
// 1. User signup
await logit.now("signups", {
  event: "New user",
  description: user.email,
  icon: "👤",
  notify: true,
  tags: { plan: user.plan },
  metadata: { userId: user.id, email: user.email },
});

// 2. Payment
await logit.now("payments", {
  event: "Payment received",
  description: `${user.email} — $${amount}`,
  icon: "💰",
  notify: true,
  tags: { plan: user.plan },
  metadata: { amount, userId: user.id },
});

// 3. Error (revenue-critical)
await logit.now("errors", {
  event: "Checkout failed",
  description: error.message,
  icon: "❌",
  notify: true,
  tags: { component: "checkout" },
  metadata: { stack: error.stack },
});

// 4. Custom milestone
await logit.now("milestones", {
  event: "100 users 🎉",
  description: "Total signup count crossed 100",
  icon: "🎉",
  notify: true,
});

Error handling

ts
import { LogitError } from "logit";

try {
  await logit.now("signups", { event: "New user", description: email });
} catch (err) {
  if (err instanceof LogitError) {
    console.error("LogIt error:", err.message, err.statusCode);
  }
  // LogIt errors should never crash your app — log and continue
}

Environment

bash
# .env
LOGIT_API_KEY=lk_live_xxxxxxxxxxxxxxxx

Try LogIt free

7-day trial. No credit card required.

Start free