Skip to content

coderaiser/koa-mongolog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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) {
    if (error) {
        console.error(error.message);
    } else {
        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

About

koa middleware for logging http queries to mongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published