Node.js / Express APM
Get the most out of Middleware OpsAI for your Node.js Express applications by using the Middleware Node.js SDK (version 2.2.0
or newer).
🚀 Key Features
- Supports function code capturing for runtime exceptions
- Works seamlessly with Express Framework
🛠️ APM Setup
Install the Middleware package:
npm install @middleware.io/node-apm --save
Initialize the tracker at the top of your entry file:
// index.js const tracker = require('@middleware.io/node-apm'); tracker.track({ serviceName: "your-service-name", accessToken: "<MW_API_KEY>", }); // Import other modules after tracker.track() const express = require('express'); // ...rest of your app
⚡ Exception Code Capturing
Register Error Handler provided by Middleware Node.js SDK to capture Exception Code
const { registerErrorHandler } = require("@middleware.io/node-apm"); registerErrorHandler(app);
⚙️ VCS Metadata Configuration (Recommended)
If your app has a .git
directory, the APM will auto-fetch repository URL, commit SHA, and other metadata for OpsAI.
If your app is containerized or does not have a .git
directory, set these environment variables to send VCS info to OpsAI (this helps generate solution PRs):
MW_VCS_COMMIT_SHA=$(git rev-parse HEAD) MW_VCS_REPOSITORY_URL=$(git config --get remote.origin.url)
These are just example commands to fetch values from Git. You can set these environment variables in any way that fits your workflow, such as through your CI/CD pipeline or other automation tools.