Hud Node.js SDK
The `hud-sdk` package provides a lightweight, low-overhead runtime sensor for Node.js applications, designed to capture real-time, function-level behavior directly from production environments. It observes performance characteristics, error behavior, and execution patterns without requiring manual instrumentation, logs, or dashboards. The SDK integrates with various developer tools, including IDEs and CI/CD pipelines, and is specifically optimized for AI-assisted development workflows (e.g., GitHub Copilot, Cursor) to ensure AI-generated code is production-safe. Current stable version is 1.8.3, with frequent updates indicated by its last publish date. It differentiates itself by offering continuous visibility directly in the developer's IDE, focusing on high-fidelity, function-level data, and adhering to strict security and privacy standards (SOC 2 Type II, ISO 27001, GDPR compliance), transmitting only anonymized metadata.
Common errors
-
Hud: Can't load Hud due to an unsupported Node.js version.
cause The application is running a Node.js version not supported by the Hud SDK.fixCheck the Hud SDK's compatibility matrix and upgrade your Node.js runtime to a supported version, then restart your service. -
Hud: SDK has initiated a graceful shutdown. Your application remains unaffected. (Error E9002)
cause The SDK failed to establish or maintain communication with the Hud backend after multiple retry attempts.fixVerify outbound network connectivity from your runtime host to `https://api-prod.hud.io`. Check firewall, proxy settings, and ensure custom SSL certificates are trusted by Node.js. -
Hud: SDK limit of instrumented functions exceeded. SDK has initiated a graceful shutdown. Your application remains unaffected. (Error E1022)
cause Your application has too many functions, exceeding the SDK's internal instrumentation limit.fixReduce the scope of instrumentation, potentially by configuring the SDK to exclude specific modules or paths. Consult Hud documentation or support for configuration options to manage instrumentation. -
I don't see any endpoints in Hud dashboard.
cause Hud's SDK did not detect or collect data for your HTTP endpoints, possibly due to `register()` being called too late, unsupported framework, or endpoints not being invoked.fixEnsure `register()` is called at the very beginning of your application. Invoke your HTTP endpoints to generate traffic. Check Hud's support matrix for your specific HTTP framework. -
Hud: 'ts-node' was detected but could not be resolved by Hud. This may happen if 'ts-node' is installed globally. Try installing it locally in your project. The SDK has initiated a graceful shutdown.
cause `ts-node` is either not installed locally or not resolvable by Hud's module loading mechanism.fixInstall `ts-node` locally in your project (`npm install ts-node`). Ensure `npx ts-node` or `node --require ts-node/register` is used to run your TypeScript application, rather than a globally installed `ts-node` or other problematic setups.
Warnings
- gotcha The `register()` call must be placed as early as possible in your application's entry file, typically before any other application code or framework imports. Delaying this call can result in incomplete or incorrect instrumentation, as Hud might miss wrapping certain functions or modules.
- breaking Running the SDK with an unsupported Node.js version will prevent it from loading and initiating graceful shutdown. This means no runtime data will be collected.
- gotcha Failure to communicate with the Hud backend due to network issues, firewall restrictions, proxy configurations, or untrusted certificates will cause the SDK to shut down gracefully.
- gotcha When using `ts-node` for TypeScript execution, Hud requires it to run in `transpileOnly` mode to avoid performance issues and ensure proper module loading. If `ts-node` is not resolvable locally, Hud will also gracefully shut down.
- gotcha The SDK has an internal limit on the number of functions it can instrument to prevent performance degradation. Exceeding this limit will cause the SDK to gracefully shut down.
Install
-
npm install hud-sdk -
yarn add hud-sdk -
pnpm add hud-sdk
Imports
- register
const Hud = require('hud-sdk'); Hud.register(...);import { register } from 'hud-sdk'; - HudClient
import { HudClient } from 'hud-sdk/client'; - * as Hud
import Hud from 'hud-sdk';
import * as Hud from 'hud-sdk';
Quickstart
import { register } from 'hud-sdk';
// Ensure this is called as early as possible in your application's entry file.
// It's crucial for Hud's auto-instrumentation to wrap functions correctly.
register({
apiKey: process.env.HUD_API_KEY ?? '',
// Optional: Provide a service name for better identification in Hud's dashboard
serviceName: process.env.SERVICE_NAME ?? 'my-nodejs-app',
// Optional: Enable debug logging if needed for troubleshooting
// debug: process.env.NODE_ENV === 'development'
});
// Example of a simple Express app to demonstrate instrumentation
import express from 'express';
const app = express();
const port = 3000;
app.get('/', (req, res) => {
console.log('Request received for /');
res.send('Hello from Hud-instrumented app!');
});
app.get('/error', (req, res) => {
console.error('Simulating an error!');
throw new Error('This is a simulated error detected by Hud!');
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});