Skip to content

cli-aware

Detect CLI clients and serve alternative responses depending on the environment
  1. Install the package using your preferred package manager

    Terminal window
    npm install cli-aware
  2. Import the CliAware class and use it in your server-side code

    +server.ts
    import CliAware from 'cli-aware';
    import type { RequestHandler } from './$types';
    export const GET: RequestHandler = ({ request }) => {
    const aware = new CliAware(request);
    if (aware.cli) {
    return new Response('hello from the cli!');
    }
    return new Response('hello from the browser!');
    };