Website • Documentation • Pricing
Treblle is an API intelligence platfom that helps developers, teams and organizations understand their APIs from a single integration point.
- Node.js:
>=14.0.0
(supports all LTS versions from 14.x onwards) - Supported Framework: Express, NestJS, Koa, Hono, Strapi, or Cloudflare Workers
stack-trace
- Error stack parsing and debugging
node-fetch
- HTTP client (Node.js environments only)- Used by: Express, NestJS, Koa, Hono (Node.js), Strapi
- Not needed: Cloudflare Workers (uses native
fetch
)
Note: Framework dependencies (Express, Koa, etc.) are peer dependencies - install the version your project uses.
Framework | Supported Versions | Node.js Requirement | Status | Notes |
---|---|---|---|---|
Express | 4.x , 5.x |
>=14.0.0 |
âś… Full Support | Both versions fully supported |
NestJS | 9.x , 10.x , 11.x |
>=16.0.0 |
âś… Full Support | Built on Express/Fastify |
Koa | 2.x , 3.x |
>=18.0.0 |
âś… Full Support | Modern async/await support |
Hono | 4.x |
>=16.0.0 |
âś… Full Support | Multi-runtime (Node.js, Bun, Deno) |
Strapi | 4.x , 5.x |
>=18.0.0 LTS |
âś… Full Support | Built on Koa |
Cloudflare Workers | Workers Runtime | Web Standards API | âś… Full Support | V8-based runtime |
You can install the Treblle JavaScript SDK via NPM. Simply run the following command:
$ npm install treblle@^2.0.0
Don't forget to load the required JS modules in your app.js like so:
const express = require("express");
const { useTreblle } = require("treblle");
- The old
apiKey
value is now calledsdkToken
to match our new naming conventions - The old
projectId
value is now calledapiKey
to match our new naming conventions showErrors
is now renamed todebug
for more clarity
// This continues to work in v2.0+
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_", // renamed from apiKey
apiKey: "_YOUR_API_KEY_", // renamed from projectId
debug: true // renamed from showErrors
});
For more details on other changes and improvements please take a look at the Changelog section.
Next, create a FREE account on https://treblle.com to get an SDK token and API key. After you have those simply initialize Treblle in your app.js file like so for Express:
const express = require("express");
const { useTreblle } = require("treblle");
const app = express();
app.use(express.json());
// Treblle automatically adds both request/response and error handling middleware
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
});
app.get("/api/users", (req, res) => {
res.json({ users: [] });
});
app.listen(3000);
Note on Middleware Ordering: Ensure Treblle is registered after body parsing middleware:
app.use(express.json()); // First: body parsing
app.use(express.urlencoded({ extended: true }));
useTreblle(app, { /* config */ }); // Then: Treblle
// Finally: your routes
app.get('/api/users', handler);
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId"], // Optional: Mask additional fields
blocklistPaths: ["admin", "health"], // Optional: Skip logging certain paths
ignoreDefaultBlockedPaths: false, // Optional: Disable default blocked paths (default: false)
debug: true, // Optional: Show Treblle errors in console (default: false)
});
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsblocklistPaths
(optional): Array of path prefixes or RegExp to exclude from loggingignoreDefaultBlockedPaths
(optional): Boolean to disable default blocked paths (default: false)debug
(optional): Boolean to show Treblle-related errors in console (default: false)
That's it. Your API requests and responses are now being sent to your Treblle project. Just by adding that line of code you get features like: auto-documentation, real-time request/response monitoring, error tracking and so much more.
const Koa = require("koa");
const KoaRouter = require("koa-router");
const KoaBody = require("koa-body");
const { koaTreblle } = require("treblle");
const app = new Koa();
const router = new KoaRouter();
// Add Treblle middleware
app.use(
koaTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
})
);
// Add other middleware
app.use(KoaBody());
// Add routes
router.get("/api/users", (ctx) => {
ctx.body = { users: [] };
});
app.use(router.routes());
app.listen(3000);
app.use(
koaTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId"], // Optional: Mask additional fields
blocklistPaths: ["admin", "health"], // Optional: Skip logging certain paths
ignoreDefaultBlockedPaths: false, // Optional: Disable default blocked paths (default: false)
debug: true, // Optional: Show Treblle errors in console (default: false)
})
);
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsblocklistPaths
(optional): Array of path prefixes or RegExp to exclude from loggingignoreDefaultBlockedPaths
(optional): Boolean to disable default blocked paths (default: false)debug
(optional): Boolean to show Treblle-related errors in console (default: false)
import { Hono } from "hono";
import { honoTreblle } from "treblle";
const app = new Hono();
// Add Treblle middleware to all routes
app.use(
"*",
honoTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
})
);
// Add your routes
app.get("/api/users", (c) => c.json({ users: [] }));
app.post("/api/users", async (c) => {
const body = await c.req.json();
return c.json({ success: true, user: body });
});
export default app;
app.use(
"*",
honoTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId"], // Optional: Mask additional fields
blocklistPaths: ["admin", "health"], // Optional: Skip logging certain paths
ignoreDefaultBlockedPaths: false, // Optional: Disable default blocked paths (default: false)
debug: true, // Optional: Show Treblle errors in console (default: false)
})
);
// Monitor only API routes
app.use(
"/api/*",
honoTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
})
);
// Or exclude specific paths
app.use(
"*",
honoTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
blocklistPaths: /^\/(health|metrics|admin)/, // Using RegExp for complex patterns
})
);
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsblocklistPaths
(optional): Array of path prefixes or RegExp to exclude from loggingignoreDefaultBlockedPaths
(optional): Boolean to disable default blocked paths (default: false)debug
(optional): Boolean to show Treblle-related errors in console (default: false)
Treblle has support for Strapi as well. Since Strapi runs on Koa under the hood, you need to define the middleware first and then enable it.
This guide is based on the strapi quickstart project, you can create it and follow by running:
npx create-strapi-app my-project --quickstart
Step 1: Create the middleware in middlewares/treblle/index.js
:
const { strapiTreblle } = require("treblle");
module.exports = (strapi) => {
return {
initialize() {
strapi.app.use(
strapiTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
})
);
},
};
};
Step 2: Enable the middleware in config/middleware.js
:
module.exports = {
settings: {
treblle: {
enabled: true,
},
},
};
// middlewares/treblle/index.js
const { strapiTreblle } = require("treblle");
module.exports = (strapi) => {
return {
initialize() {
strapi.app.use(
strapiTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId"], // Optional: Mask additional fields
blocklistPaths: ["webhooks", "uploads"], // Optional: Skip logging certain paths
ignoreDefaultBlockedPaths: false, // Optional: Disable default blocked paths (default: false)
debug: true, // Optional: Show Treblle errors in console (default: false)
ignoreAdminRoutes: ["admin", "content-manager", "upload"], // Optional: Ignore admin routes (default: ["admin", "content-type-builder", "content-manager"])
})
);
},
};
};
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsblocklistPaths
(optional): Array of path prefixes or RegExp to exclude from loggingignoreDefaultBlockedPaths
(optional): Boolean to disable default blocked paths (default: false)debug
(optional): Boolean to show Treblle-related errors in console (default: false)ignoreAdminRoutes
(optional): Array of admin route prefixes to ignore (default:["admin", "content-type-builder", "content-manager"]
)
Note: The ignoreAdminRoutes
option is Strapi-specific and helps avoid logging internal admin panel requests that are typically not part of your public API.
Cloudflare Workers require bundling external packages. You need a bundler (Webpack or Rollup) to bundle Treblle with your worker code.
Setup Requirements:
- A bundler (Webpack/Rollup) to bundle dependencies
- Polyfills for Node.js modules not available in Workers Runtime
Step 1: Configure Wrangler and Webpack:
# wrangler.toml
type = "webpack"
webpack_config = "webpack.config.js"
[build.upload]
format = "service-worker"
// webpack.config.js
module.exports = {
entry: "./index.js",
target: "webworker",
mode: "production",
output: {
filename: "worker.js",
},
resolve: {
fallback: {
os: false, // Required: Treblle uses Node.js modules not available in Workers
url: false, // Required: These are polyfilled as empty modules
},
},
};
Step 2: Basic Service Worker setup:
// worker.js
const { serviceWorkerTreblle } = require("treblle");
// Initialize Treblle
const treblle = serviceWorkerTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
});
// Wrap your fetch handler
addEventListener(
"fetch",
treblle((event) => {
event.respondWith(
new Response("Hello worker!", {
headers: { "content-type": "text/plain" },
})
);
})
);
Step 3: Service Worker with all options:
const treblle = serviceWorkerTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["key1", "key2"], // Optional: Mask additional fields
debug: true, // Optional: Show Treblle errors in console (default: false)
});
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsdebug
(optional): Boolean to show Treblle-related errors in console (default: false)
Note: blocklistPaths
is not available for Cloudflare Workers as path filtering should be handled in your worker logic.
Setup Requirements:
- Same bundler setup as Service workers
- ES modules support for import/export syntax
Step 1: Basic Module Worker setup:
// worker.js
import { moduleWorkerTreblle } from "treblle";
// Initialize Treblle
const treblle = moduleWorkerTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
});
export default {
// Wrap your fetch handler
fetch: treblle(async (request, env, context) => {
// Your API logic here
const url = new URL(request.url);
if (url.pathname === "/api/users") {
return new Response(JSON.stringify({ users: [] }), {
headers: { "content-type": "application/json" },
});
}
return new Response("Not found", { status: 404 });
}),
};
Step 2: Module Worker with all options:
const treblle = moduleWorkerTreblle({
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["key1", "key2"], // Optional: Mask additional fields
debug: true, // Optional: Show Treblle errors in console (default: false)
});
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsdebug
(optional): Boolean to show Treblle-related errors in console (default: false)
Important Notes:
- Treblle uses Node native libraries (
os
&url
) for other integrations that aren't supported in Cloudflare Workers Runtime - These are polyfilled as empty modules since they're not used in the Workers integration
- See the webpack configuration above for required polyfills
- Example setup with Modules and CommonJS: Cloudflare's official example
NestJS uses Express under the hood, so Treblle integrates by accessing the underlying Express instance.
// main.ts
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { useNestTreblle } from "treblle";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// Get the underlying Express instance
const expressInstance = app.getHttpAdapter().getInstance();
// Add Treblle middleware
useNestTreblle(expressInstance, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
});
await app.listen(3000);
}
bootstrap();
useNestTreblle(expressInstance, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId"], // Optional: Mask additional fields
blocklistPaths: ["admin", "health"], // Optional: Skip logging certain paths
ignoreDefaultBlockedPaths: false, // Optional: Disable default blocked paths (default: false)
debug: true, // Optional: Show Treblle errors in console (default: false)
});
// main.ts
import { ConfigService } from "@nestjs/config";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
const expressInstance = app.getHttpAdapter().getInstance();
useNestTreblle(expressInstance, {
sdkToken: configService.get("TREBLLE_SDK_TOKEN"),
apiKey: configService.get("TREBLLE_API_KEY"),
debug: configService.get("NODE_ENV") !== "production",
});
await app.listen(3000);
}
Available options:
sdkToken
(required): Your Treblle SDK tokenapiKey
(required): Your Treblle API keyadditionalFieldsToMask
(optional): Array of field names to mask in addition to default fieldsblocklistPaths
(optional): Array of path prefixes or RegExp to exclude from loggingignoreDefaultBlockedPaths
(optional): Boolean to disable default blocked paths (default: false)debug
(optional): Boolean to show Treblle-related errors in console (default: false)
**Important Notes:
- Must be called after
NestFactory.create()
but beforeapp.listen()
- Only works with Express adapter (default NestJS adapter)
- For Fastify adapter, use regular Express integration with Fastify-specific setup
If you want to run Treblle only in production, you can rely on the environment variables, or use a similar approach via config.
const app = express();
app.use(express.json());
if (process.env.NODE_ENV === "production") {
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
});
}
If you want to expand the list of fields you want to hide, you can pass property names you want to hide by using the additionalFieldsToMask
setting like in the example below.
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["secretField", "highlySensitiveField"],
});
For easier debugging when sending the data to Treblle errors are visible by default, you can control it via the debug
flag, you can disable the errors with debug
set to false
:
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
debug: false,
});
Treblle automatically masks sensitive fields in request and response bodies. The following fields are masked by default:
password
pwd
secret
password_confirmation
passwordConfirmation
cc
card_number
cardNumber
ccv
ssn
credit_score
creditScore
You can add additional fields to mask using the additionalFieldsToMask
option:
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
additionalFieldsToMask: ["customSecret", "internalId", "sessionToken"],
});
Treblle automatically blocks common browser requests and static files from being logged to avoid noise in your API monitoring. The following paths and patterns are blocked by default:
Specific Files:
favicon.ico
- Browser icon requestsrobots.txt
- Search engine crawler instructionssitemap.xml
- Website sitemap filesmanifest.json
- Progressive Web App manifestsw.js
/service-worker.js
- Service worker filesapple-touch-icon*
- iOS home screen iconsbrowserconfig.xml
- IE/Edge configurationcrossdomain.xml
- Flash crossdomain policyads.txt
- Advertising policy file
Directory Patterns:
/.well-known/
- IETF well-known URIs (certificates, etc.)/static/
- Static file directories/assets/
- Asset directories/public/
- Public file directories/images/
- Image directories/css/
- Stylesheet directories/js/
- JavaScript directories
File Extensions:
- Static assets:
.css
,.js
,.png
,.jpg
,.jpeg
,.gif
,.svg
,.ico
- Fonts:
.woff
,.woff2
,.ttf
,.eot
If you want to log these requests (for example, to monitor static file access), you can disable the default blocking:
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
ignoreDefaultBlockedPaths: true, // Disable automatic blocking
blocklistPaths: ["favicon.ico"], // Manually specify what to block
});
By default, both the default blocked paths and your custom blocklistPaths
are applied:
useTreblle(app, {
sdkToken: "_YOUR_SDK_TOKEN_",
apiKey: "_YOUR_API_KEY_",
blocklistPaths: ["admin", "health"], // Custom blocks
// Default blocks (favicon.ico, robots.txt, etc.) still apply
});
Block specific paths or patterns from being logged:
// Block specific paths (string array)
blocklistPaths: ["admin", "health", "metrics"];
// Block using RegExp for complex patterns
blocklistPaths: /^\/(admin|health|metrics)/;
// Mixed array with strings and RegExp
blocklistPaths: ["admin", /^\/api\/v1\/internal/];
- Express v5 Support: Full compatibility with both Express 4.x and 5.x
- Improved Express Integration: Replaced invasive method patching with standard middleware patterns
- Better Error Handling: Uses proper Express error middleware instead of overriding internal methods
- Dramatically improved networking performance
- Dramatically improved memory usage and consumption
- Dramatically improved masking performance
- Added support for Hono
- Extended support for Cloudflare Workers
- Added built-in endpoint detection
- Improved Debugging
- Improved Readme with more examples
If you continue to experience issues:
- Enable
debug: true
and check console output - Verify your SDK token and API key are correct in Treblle dashboard
- Test with a simple endpoint first
- Check Treblle documentation for the latest updates
- Contact support at https://treblle.com or email [email protected]
If you have problems of any kind feel free to reach out via https://treblle.com or email [email protected] and we'll do our best to help you out.
Copyright 2025, Treblle Inc. Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php