Skip to content
Firecrawl Docsv2
Firecrawl Docs
Node.js

Bun

Use Firecrawl with Bun to build fast web scraping and search servers.

Prerequisites

Install the SDK

bun add firecrawl

Add your API key to .env:

FIRECRAWL_API_KEY=fc-YOUR-API-KEY

Search the web

Bun has a built-in HTTP server. Create index.ts:

import { Firecrawl } from "firecrawl";

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });

Bun.serve({
  port: 3000,
  async fetch(req) {
    const url = new URL(req.url);

    if (req.method === "POST" && url.pathname === "/search") {
      const { query } = await req.json();
      const results = await firecrawl.search(query, { limit: 5 });
      return Response.json(results);
    }

    return new Response("Not found", { status: 404 });
  },
});

console.log("Server running on port 3000");

Run it:

bun run index.ts

Scrape a page

Add a /scrape route to the same server:

if (req.method === "POST" && url.pathname === "/scrape") {
  const { url: targetUrl } = await req.json();
  const result = await firecrawl.scrape(targetUrl);
  return Response.json(result);
}

Interact with a page

Use interact to control a live browser session — click buttons, fill forms, and extract dynamic content.

if (req.method === "POST" && url.pathname === "/interact") {
  const { url: targetUrl } = await req.json();

  const result = await firecrawl.scrape(targetUrl, { formats: ['markdown'] });
  const scrapeId = result.metadata?.scrapeId;

  await firecrawl.interact(scrapeId, { prompt: 'Search for iPhone 16 Pro Max' });
  const response = await firecrawl.interact(scrapeId, { prompt: 'Click on the first result and tell me the price' });

  await firecrawl.stopInteraction(scrapeId);

  return Response.json({ output: response.output });
}

Script usage

Use Firecrawl in a standalone Bun script:

import { Firecrawl } from "firecrawl";

const app = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const results = await app.search("firecrawl web scraping", { limit: 5 });
console.log(results);
bun run search.ts

Next steps

Was this page helpful?Suggest editsRaise issue