Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
dist v1.0.6 Nov 18, 2019
examples Add steps to the Express example Jan 7, 2020
src Report mysql queries Nov 12, 2019
tests Add scope manager Sep 30, 2019
LICENSE Add packages/node Aug 5, 2019
README.md Update readme Nov 7, 2019
babel.config.js Fix Jest to work with TypeScript Sep 2, 2019
jest.config.js Use ts-jest Sep 2, 2019
package.json v1.0.6 Nov 18, 2019
rollup.config.js Update readme Nov 7, 2019
tsconfig.json Extract base tsconfig Sep 2, 2019
tslint.json Fix Jest to work with TypeScript Sep 2, 2019

README.md

Airbrake for Node.js

Build Status

This is the JavaScript notifier for capturing errors in Node.js and reporting them to Airbrake. For web browsers there is a separate package.

Installation

airbrake can be installed using yarn:

yarn add @airbrake/node

or using npm:

npm install @airbrake/node

Example configurations can be found in examples, including:

Basic Usage

First you need to initialize the notifier with the project id and API key taken from Airbrake.io:

import { Notifier } from '@airbrake/browser';

const airbrake = new Notifier({
  projectId: 1,
  projectKey: 'REPLACE_ME',
  environment: 'production',
});

Then you can send a textual message to Airbrake:

let promise = airbrake.notify(`user id=${user_id} not found`);
promise.then(function(notice) {
  if (notice.id) {
    console.log('notice id', notice.id);
  } else {
    console.log('notify failed', notice.error);
  }
});

Or report catched errors directly:

try {
  // This will throw if the document has no head tag
  document.head.insertBefore(document.createElement('style'));
} catch(err) {
  airbrake.notify(err);
  throw err;
}

Alternatively, you can wrap any code which may throw errors using the client's wrap method:

let startApp = function() {
  // This will throw if the document has no head tag.
  document.head.insertBefore(document.createElement('style'));
}
startApp = airbrake.wrap(startApp);

// Any exceptions thrown in startApp will be reported to Airbrake.
startApp();

or use call shortcut:

let startApp = function() {
  // This will throw if the document has no head tag.
  document.head.insertBefore(document.createElement('style'));
}

airbrake.call(startApp);

Node.js request and proxy

In order to use request HTTP client you can pass request option which accepts request wrapper:

const airbrake = new Notifier({
  ...
  request: request.defaults({'proxy':'http://localproxy.com'})
});

Contributing

Install dependencies:

yarn install

Run unit tests:

yarn test

Build project:

yarn build

Credits

Airbrake is maintained and funded by airbrake.io

Thank you to all the contributors.

The names and logos for Airbrake are trademarks of Airbrake Technologies Inc.

License

Airbrake is Copyright © 2008-2017 Airbrake Technologies Inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

You can’t perform that action at this time.