npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

airbrake-hapi

v2.0.0

Published

A Hapi Plugin that automatically sends internal server errors to Airbrake.io

Downloads

5

Readme

Airbrake Hapi

A Hapi Plugin that automatically sends internal server errors to Airbrake.io.

Compatibility

Version 1.0.x -> Hapi 8.x
Version 2.x -> Hapi 10.x and Higher

Usage

To use this plugin you need an Airbrake account. Login and navigate to your project, and get your API key:

dashboard

You will also need your project ID, which can be found in the URL of your project:

https://yyyyyyy.airbrake.io/projects/XXXXXX (The X's)

Once you have those two pieces of data, you can go ahead and get started:

npm install airbrake-hapi --save

Then:

var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ host: 'localhost' });

var options = {
	id: 'airbrake_id_here',
    key: 'airbrake_api_key_here',
    notifierURL: 'url_for_application',	
    name: 'application name',
    version: '1.x'
};

server.register({
    register: require('airbrake-hapi'),
    options: options
}, function (err) {
    if (err) {
        console.error(err);
    } else {
        server.start(function () {
            console.info('Server started at ' + server.info.uri);
        });
    }
});

Required Options:

  • id - The Project ID from Airbrake
  • key - The Project API Key

Optional:

  • notifierURL - A URL to tell Airbrake what this project is.
  • name - The Application Name
  • version - The current application version. Airbrake Hapi will automatically try and set this to the current Git Hash, if you are using Git. It runs git rev-parse HEAD (run it yourself to see what it returns).

Events

On the plugin is registered, you can listen for events to let you know when an error has been sent to Airbrake. You first need to get the plugin reference, and then you can add your event listener for success sent

airbrake = server.plugins['airbrake-hapi'].airbrake
airbrake.on('sent', function(event) {
	console.log('Sent to Airbrake!', event)
	/*
	Prints:
	{id: '323423094820', url: 'https://airbrake.io/locate/323423094820'}
	*/
});

In the case of an error, you can also listen for error:

airbrake = server.plugins['airbrake-hapi'].airbrake
airbrake.on('error', function(err) {
	console.log('Error sending to Airbrake!', err)
});

This does not track deploys, but maybe it could.

Development

Airbrake Hapi is written in CoffeeScript, because I enjoy the easier to use syntax over pure javascript. However, the project is compiled to Javascript on prepublish:

"prepublish":"coffee -o bin -c lib/*.coffee"

You can use this project for any Node project, but development needs to be in CoffeeScript.

Airbrake Hapi uses the Notifier v3 to send issues to Airbrake. The v3 API accepts JSON, which makes the code much simpler and easier.

The bulk of the code is in /lib/airbrake.coffee, which is the class that handles the error parsing and sending of the requests.

/lib/index.coffee is used to stage the Hapi Plugin, which enables simple setup.

Tests

There are tests located in test. These are broken into unit and integration test. These tests can be run easily with make. If you contribute, please make sure to add a test and ensure all tests pass. Of course, to run the integration tests, you will have to have your own id and key for Airbrake.

If you don't, but really think your tests should pass, send a pull request, and I'll run it with my own credentials.

Code Coverage

Running make cov will run the code coverage. Ensure all tests pass first. This will instrument and open a window showing the result. Since this is such a small project, code coverage is 100%. Let's keep it that way.

Contributing

Send a pull request or open an issue! This is being used in production and fitted towards my needs, but can easily be expanded.

Changelog

Version 2.0.0

  • Updated Hapi to be a peer dependency. Allow for any version of Hapi.

Version 1.0.2

  • Fixed compiling of coffee-script

Version 1.0.0

  • Initial Release