Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hapijs getting started good good-console error reporter must specify events to filter on

I'm just starting to learn Hapijs following getting started tutorial with this example:

var Hapi = require('hapi');
var Good = require('good');

var server = new Hapi.Server();
server.connection({ port: 3000 });

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        reply('Hello, world!');
    }
});

server.route({
    method: 'GET',
    path: '/{name}',
    handler: function (request, reply) {
        reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
    }
});

server.register({
    register: Good,
    options: {
        reporters: [{
            reporter: require('good-console'),
            args:[{ log: '*', response: '*' }]
        }]
    }
}, function (err) {
    if (err) {
        throw err; // something bad happened loading the plugin
    }

    server.start(function () {
        server.log('info', 'Server running at: ' + server.info.uri);
    });
});

when I run

node server

I've got

/home/user/hapi/node_modules/good/node_modules/hoek/lib/index.js:683
    throw new Error(msgs.join(' ') || 'Unknown error');
          ^
Error: reporter must specify events to filter on

Can you help me, please ?

like image 994
Whisher Avatar asked Apr 08 '15 08:04

Whisher


1 Answers

The documentation is outdated. There were some breaking changes in good 6.0.0. The module good-console has a new version, however it is not published on npm yet. You can use the master branch though by specifying the GitHub repository in package.json:

"good-console": "hapijs/good-console"

You will also need to change the configuration to:

options: {
    reporters: [{
        reporter: require('good-console'),
        events: {
            response: '*',
            log: '*'
        }
    }]
}

EDIT: Version 5.0.0 of good-console has been released. The documentation was also updated.

like image 181
Gergo Erdosi Avatar answered Sep 20 '22 14:09

Gergo Erdosi