npm install --save koay-ua
# or
cnpm install --save koay-ua
const Koa = require('koa');
const ua = require('koay-ua');
const app = new Koa();
ua.middleware(app);
app.use((ctx) => {
ctx.userAgent = ctx.parseUserAgent();
});
// or
app.use((ctx) => {
ctx.userAgent = ua(ctx.headers['user-agent']);
});