Native Node.js HTTP
Add ServerDevTools to a server created with node:http.
Prerequisites
Use Node.js 20 or newer and keep the SDK initialization file separate from the application entry point so it can be preloaded.
Initialize
import ServerDevTools from "server-devtools";
export const devtools = new ServerDevTools({
auth: {
username: process.env.SERVER_DEVTOOLS_USERNAME!,
password: process.env.SERVER_DEVTOOLS_PASSWORD!,
},
});
await devtools.start();Mount and run
import { createServer } from "node:http";
import { devtools } from "../server-devtools";
createServer((req, res) => {
devtools.middleware(req, res, () => {
res.statusCode = req.url === "/hello" ? 200 : 404;
res.end(req.url === "/hello" ? "hello" : "not found");
});
}).listen(3000);npx tsx --import ./server-devtools.ts src/main.tsOpen http://localhost:3000/_devtools, authenticate, and request /hello.
Troubleshooting
If the route works but no trace is recorded, confirm that the preload command ran the initialization file and that await devtools.start() completed before the server was created.
Last updated on