Skip to main content
Metlo’s Node.js agent provides native support for Express applications through automatic instrumentation.

Installation

Install the Metlo package from npm:
npm install metlo

Quick Start

Add Metlo to your Express application by requiring it at the start of your main script:
var metlo = require("metlo")
metlo("<YOUR_METLO_API_KEY>", "<YOUR_METLO_COLLECTOR_URL>")

// Then initialize Express as usual
const express = require("express")
const app = express()

app.get("/", (req, res) => {
  res.send("Hello World!")
})

app.listen(3000)
The metlo() call must be placed before you require Express and set up your application. This allows Metlo to instrument the Express framework properly.

Configuration

Required Parameters

apiKey
string
required
Your Metlo API key for authentication with the collector
collectorUrl
string
required
The URL of your Metlo collector instance (e.g., https://collector.metlo.com)

Optional Configuration

You can pass an optional configuration object as the third parameter:
var metlo = require("metlo")
metlo("<YOUR_METLO_API_KEY>", "<YOUR_METLO_COLLECTOR_URL>", {
  apiHost: "https://api.example.com",
})
apiHost
string
Override the host value sent in trace data. Useful when your application is behind a proxy.

How It Works

Metlo’s Express integration uses require-in-the-middle to automatically instrument Express’s response methods:
  1. Intercepts responses - Patches res.send(), res.json(), res.jsonp(), and res.sendFile()
  2. Captures request/response data - Collects headers, body, query parameters, and metadata
  3. Asynchronous transmission - Sends data to Metlo collector using a worker pool

Captured Data

For each request, Metlo captures: Request:
  • URL (host, path, query parameters)
  • HTTP method
  • Headers
  • Request body
  • Source IP and port
Response:
  • Status code
  • Headers
  • Response body
  • Destination IP and port
Metadata:
  • Environment (from process.env.NODE_ENV)
  • Source identifier: node/express
  • Timestamp

Example with TypeScript

import metlo from "metlo"
metlo(process.env.METLO_API_KEY!, process.env.METLO_COLLECTOR_URL!)

import express from "express"
const app = express()

app.use(express.json())

app.post("/api/users", (req, res) => {
  // Your application logic
  res.json({ success: true })
})

app.listen(3000, () => {
  console.log("Server running on port 3000")
})

Troubleshooting

Ensure that:
  • metlo() is called before requiring Express
  • Your collector URL is correct and accessible
  • Your API key is valid
  • Check console for any error messages
Metlo uses a worker pool to send data asynchronously, minimizing impact on request latency. The worker pool size is automatically set based on CPU count.
Metlo captures the full response body. For very large responses, consider implementing body size limits in your application.

Requirements

  • Node.js >= 11.7.0
  • Express (any version)

Next Steps

View API Inventory

See your discovered APIs in the Metlo dashboard

Configure Alerts

Set up alerts for sensitive data exposure

Build docs developers (and LLMs) love