
cli-aware
Detect CLI clients and serve alternative responses depending on the environment
Quick setup
Section titled “Quick setup”-
Install the package using your preferred package manager
Terminal window npm install cli-awareTerminal window pnpm add cli-awareTerminal window yarn add cli-awareTerminal window bun add cli-aware -
Import the
CliAwareclass 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!');};router.ts import CliAware from 'cli-aware';export function GET(request: Request) {const aware = new CliAware(request);if (aware.cli) {return new Response('hello from the cli!');}return new Response('hello from the browser!');}router.ts import CliAware from 'cli-aware';export default {fetch(request: Request) {const aware = new CliAware(request);if (aware.cli) {return new Response('hello from the cli!');}return new Response('hello from the browser!');}};