Import Hud as Early as Possible

To ensure Hud can track all of your code, including your HTTP and queue frameworks, it's critical to initialize it before any of your application code loads.

Why Early Import Unlocks Full Power

Hud works by mapping and instrumenting your code at runtime.
When you import it early:

  • All of your code is tracked, from the very first function call.
  • HTTP frameworks like Express, Fastify, and Koa are automatically monitored.
  • Queue frameworks like Kafka and SQS are monitored out of the box.
  • You get complete call graphs, accurate durations, and contextual error attribution — right from application's startup.

📘

The earlier Hud starts, the more it sees — and the more insight you get.



How to Import Hud the Right Way

Preferred: Preload Hud with --require

This guarantees Hud is loaded before your app:

node --require ./hud-init.js [YOUR_ENTRY_POINT].js
npx ts-node --require ./hud-init.ts [YOUR_ENTRY_POINT].ts
nest start --exec "node --require ./hud-init.js"
// NOTE: Next.js is not fully supported yet, endpoints data will not be collected

// Create a file called instrumentation.ts with the following code:

export async function register() {
	require('./hud-init.js');
}
//project.json

"my-app": {
  "targets": {
    "serve": {
      "executor": "@nx/js:node",
      "options": {
        "runtimeArgs": ["--require", "./hud-init.js"],
        //...
      },
    },
  }
}
// If using `npm run`, check your package.json and modify the relevant script that runs your backend:
"scripts": {
  "dev": "node --require ./hud-init.js index.js"
}

Or: Import at the Very Top of Your Entry File

Make sure Hud is the first thing imported, before any other module or logic runs.

require('./hud-init.js'); // must come first
// …rest of your app
import './hud-init.ts';   // must come *before* any other imports
// …rest of your app


What Happens If You Import Too Late?

Hud will still try its best — but it may miss important parts of your system.


Pro Tips

  1. Always import Hud before any application logic.
  2. Use register({ verbose: true }) to debug early imports.
  3. --require is foolproof — we highly recommend it.
  4. Chat with our support team or email us at [email protected] anytime — we’re happy to help!