Airbrake for Node.js
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 {
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() {
document.head.insertBefore(document.createElement('style'));
}
startApp = airbrake.wrap(startApp);
startApp();
or use call
shortcut:
let startApp = function() {
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.