A Nest module wrapper for bugsnag

Usage no npm install needed!

<script type="module">
  import schramautopartsNestBugsnag from 'https://cdn.skypack.dev/@schramautoparts/nest-bugsnag';


Nest Logo

A Nest module wrapper for bugsnag logger.

NPM Version Package License


A Nest module wrapper for bugsnag-js logger.


$ npm i @bugsnag/plugin-express --save
$ npm i @nkaurelien/nest-bugsnag --save

Quick Start

Import the BugsnagModule into the module. For example AppModule:

import { Module } from '@nestjs/common';
import { BugsnagModule } from '@nkaurelien/nest-bugsnag';
import BugsnagPluginExpress from '@bugsnag/plugin-express'

  imports: [
          apiKey: '<API_KEY>',
          plugins: [BugsnagPluginExpress],
export class AppModule { }

In the main.ts file, change the HTTP platform to use express

// change
const app = await NestFactory.create(AppModule);
// to
const app = await NestFactory.create<NestExpressApplication>(AppModule);

This handles any errors that Express catches


Then you can inject BugsnagService. Example:

import { Controller } from '@nestjs/common';
import { BugsnagService } from '@nkaurelien/nest-bugsnag';

export class CatsController {
  constructor(private readonly logger: BugsnagService) { }

BugsnagService has instance property which wrap bugsnag client. So you can access it by calling:

try {
} catch (e) {

In your controller, you can call req.bugsnag.notify(err) which will include information about the request in the error report. For example:

 getHello(@Request() req): string {
         new Error('First Error'),
         function (event) {
             // event.addMetadata('product', product)
     return 'Hello World!';

Note that BugsnagModule is a global module, it will be available in all you feature modules.

Async configuration Sample

import { Module } from '@nestjs/common';
import { BugsnagModule } from '@nkaurelien/nest-bugsnag';

  imports: [
      useFactory: (configService: ConfigService) => ({
        // options
      inject: [ConfigService],
export class AppModule { }

The factory might be async and is able to inject dependencies through the inject option.


bugsnagJs, nestJs, logger