koa-mongolog

1.0.0 • Public • Published

Koa-Mongolog

Koa middleware for logging http queries to mongoDB.

Mongolog saves data this way:

{
    ip: '<clients ip address>',
    date: '<short date>',
    urls: {
        url: '<url to resource>',
        count: '<count of requests>'
    }
}

Mongolog data could be read from command line by mongolog-cli.

Install

npm i koa-mongolog --save

Hot to use?

Mongolog could be used as koa middleware this way.

    
var mongolog    = require('mongolog'),
    koa         = require('koa'),
    mongo       = require('mongodb').MongoClient,
    
    url         = 'mongodb://localhost:27017/myproject',
    port    = 1337,
    
    app     = koa();

mongo.connect(url, function(error, db) {
    app.use(mongolog({
        db: db
    }));
    
    app.use(function*(next) {
        console.log(this.request.url);
        yield next;
    });
    
    app.listen(port);
    console.log('http://localhost:%s', port); 
});

See also

License

MIT

Package Sidebar

Install

npm i koa-mongolog

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • coderaiser