Treblle with Node.js
Treblle provides a unified SDK for Node.js that works with all major frameworks. This page covers the core Node.js integration and points to framework-specific guides.
Requirements
Section titled “Requirements”- Node.js:
>=14.0.0(14.x LTS or higher recommended)
Installation
Section titled “Installation”npm install treblle@^2.0.0Setting up credentials
Section titled “Setting up credentials”Create a free account on treblle.com to get your credentials:
sdkToken(SDK Token)apiKey(API Key)
Add these to your .env file:
TREBLLE_SDK_TOKEN=your_sdk_tokenTREBLLE_API_KEY=your_api_keyChoose Your Framework
Section titled “Choose Your Framework”The Treblle SDK works with popular Node.js frameworks:
Express (Most Popular)
Section titled “Express (Most Popular)”Full Express integration guide →
const { useTreblle } = require("treblle");useTreblle(app, { sdkToken: "...", apiKey: "..." });Fastify (High Performance)
Section titled “Fastify (High Performance)”Full Fastify integration guide →
const { fastifyTreblle } = require("treblle");await fastify.register(fastifyTreblle, { sdkToken: "...", apiKey: "..." });Koa (Minimalist)
Section titled “Koa (Minimalist)”const { koaTreblle } = require("treblle");app.use(koaTreblle({ sdkToken: "...", apiKey: "..." }));NestJS (Full-Featured)
Section titled “NestJS (Full-Featured)”Full NestJS integration guide →
const { useNestTreblle } = require("treblle");useNestTreblle(expressInstance, { sdkToken: "...", apiKey: "..." });Strapi (Headless CMS)
Section titled “Strapi (Headless CMS)”Full Strapi integration guide →
const { strapiTreblle } = require("treblle");strapiTreblle({ sdkToken: "...", apiKey: "..." });Next.js (React Framework)
Section titled “Next.js (React Framework)”Full Next.js integration guide →
import { withTreblle } from "@treblle/next/integrations/nextjs";export const GET = withTreblle(async () => NextResponse.json({}));Other Frameworks
Section titled “Other Frameworks”- AdonisJS - Recommended using unified SDK
- SailsJS - Recommended using unified SDK with Koa
- Directus - Headless CMS integration
Core Configuration
Section titled “Core Configuration”All frameworks use the same unified configuration:
{ sdkToken: "required", // Your SDK Token apiKey: "required", // Your API Key additionalFieldsToMask: [], // Optional: Extra fields to mask blocklistPaths: [], // Optional: Paths to exclude ignoreDefaultBlockedPaths: false, // Optional: Disable defaults debug: false // Optional: Show errors}Automatic Field Masking
Section titled “Automatic Field Masking”The following fields are automatically masked:
password,pwd,secret,password_confirmation,passwordConfirmationcc,card_number,cardNumber,ccvssncredit_score,creditScore
Add custom fields:
additionalFieldsToMask: ["apiKey", "internalId", "sessionToken"]Default Blocked Paths
Section titled “Default Blocked Paths”These paths are automatically skipped:
- Files:
favicon.ico,robots.txt,sitemap.xml,manifest.json,sw.js - Directories:
/.well-known/,/static/,/assets/,/public/,/images/ - Extensions:
.css,.js,.png,.jpg,.gif,.svg,.ico,.woff,.ttf
Disable defaults:
ignoreDefaultBlockedPaths: trueProduction Setup
Section titled “Production Setup”Run Treblle only in production:
if (process.env.NODE_ENV === "production") { // Initialize Treblle}Debugging
Section titled “Debugging”Enable debug mode:
{ sdkToken: "...", apiKey: "...", debug: true // Show errors in console}