Skip to content

Quickstarts > Using Bun / Deno

Using Bun / Deno ​

Installation ​

Install UAParser.js using your runtime's package manager:

sh
$ bun add ua-parser-js
sh
$ deno add npm:ua-parser-js

Usage ​

Pass the incoming request headers to UAParser.js:

js
import { UAParser } from 'ua-parser-js';

Bun.serve({
    port: 3000,
    fetch(request) {
        const { browser, device } = UAParser(request.headers);

        return Response.json({
            browser: browser.name,
            mobile: device.is('mobile'),
        });
    },
});
ts
import { UAParser } from 'ua-parser-js';

Deno.serve({ port: 3000 }, (request) => {
    const { browser, device } = UAParser(request.headers);

    return Response.json({
        browser: browser.name,
        mobile: device.is('mobile'),
    });
});

Run the server with bun run server.js or deno run --allow-net server.ts, then open http://localhost:3000.

References ​

UAParser.js v2 is licensed under AGPLv3 or PRO licenses.