tracepure
v1.0.2
Published
A lightweight JavaScript utility that cleans and formats Node.js stack traces for better debugging readability.
Maintainers
Readme
cleanstack
A lightweight JavaScript utility that cleans and formats Node.js stack traces for better debugging readability.
Installation
npm install tracepureUsage
import cleanstack from "tracepure";
try {
getUser(42);
} catch (err) {
console.error(cleanstack(err));
}Pretty Output
❌ User not found
File: controllers/user.js
Line: 42
Function: getUser
Stack:
→ at getUser (controllers/user.js:42:12)
→ at main (app.js:15:3)JSON Output
const info = cleanstack(err, { json: true });
// {
// message: "User not found",
// file: "/app/controllers/user.js",
// line: 42,
// column: 12,
// func: "getUser",
// stack: ["at getUser (controllers/user.js:42:12)"]
// }Middleware
Use as Express error middleware:
import express from "express";
import cleanstack from "tracepure";
const app = express();
app.use(cleanstack.middleware());
// API requests get JSON, browser requests get pretty console outputWhat It Removes
Lines containing these patterns are automatically filtered:
node:internalinternal/modulesprocessTicksAndRejectionsnode_modules/...
API
cleanstack(error, options?)
| Param | Type | Default | Description |
| ------- | ------- | ------- | ---------------------------------- |
| error | Error | required | Error object to clean |
| options | object | {} | See below |
Options
| Option | Type | Default | Description |
| ------ | ------- | ------- | ------------------------------------ |
| json | boolean | false | Return structured object instead of string |
cleanstack.middleware()
Returns Express error middleware.
Test
node test.jsLicense
MIT
