A lightweight and typed utility for parsing JavaScript and NestJS stack traces into structured, readable objects.
npm install nestjs-stack-parser
nestjs-stack-parser
helps you convert raw stack traces—like those from NestJS or plain JavaScript errors—into structured objects. It parses:
- The error type (e.g.,
TypeError
,ForbiddenException
) - The error message
- The full stack trace, broken down into:
- Class name (if present)
- Method name
- File path
- Line and column numbers
import { parseStack } from "nestjs-stack-parser";
try {
// some code that throws
} catch (err) {
const parsed = parseStack(err.stack, { excludeNodeModules: true });
console.log(parsed);
}
{
type: 'TypeError',
error: "Cannot read properties of undefined (reading 'qd')",
stack: [
{
at: 'AppService.getHello',
className: 'AppService',
methodName: 'getHello',
file: '/app/src/app.service.ts',
line: 13,
column: 20
},
// ...more frames
]
}
- Type:
boolean
- Default:
false
- If
true
, stack frames fromnode_modules
will be excluded.
This project uses Jest for unit tests. To run tests:
npm test
├── src/
│ └── parseStack.ts
├── dist/
├── test/
│ └── parseStack.test.ts
├── package.json
├── tsconfig.json
├── jest.config.js
└── README.md
MIT © Nicolas LEROY