nestjs-stack-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

nestjs-stack-parser

A lightweight and typed utility for parsing JavaScript and NestJS stack traces into structured, readable objects.


📦 Installation

npm install nestjs-stack-parser

🔍 What It Does

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

🛠️ Usage

import { parseStack } from "nestjs-stack-parser";

try {
  // some code that throws
} catch (err) {
  const parsed = parseStack(err.stack, { excludeNodeModules: true });
  console.log(parsed);
}

Example Output

{
  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
  ]
}

⚙️ Options

excludeNodeModules

  • Type: boolean
  • Default: false
  • If true, stack frames from node_modules will be excluded.

🧪 Testing

This project uses Jest for unit tests. To run tests:

npm test

📁 Project Structure

├── src/
│   └── parseStack.ts
├── dist/
├── test/
│   └── parseStack.test.ts
├── package.json
├── tsconfig.json
├── jest.config.js
└── README.md

📄 License

MIT © Nicolas LEROY


🌐 Links

Package Sidebar

Install

npm i nestjs-stack-parser

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

7.2 kB

Total Files

12

Last publish

Collaborators

  • nikolas03