> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Bun

> Bun で Firecrawl を使い、高速な Web スクレイピングおよび検索サーバーを構築します。

<div id="prerequisites">
  ## 前提条件
</div>

* Bun 1.0+
* Firecrawl APIキー — [無料で取得できます](https://www.firecrawl.dev/app/api-keys)

<div id="install-the-sdk">
  ## SDKをインストール
</div>

```bash theme={null}
bun add firecrawl
```

`.env`にAPI keyを追加します：

```bash theme={null}
FIRECRAWL_API_KEY=fc-YOUR-API-KEY
```

<div id="search-the-web">
  ## Web を検索する
</div>

Bun には組み込みの HTTP サーバーがあります。`index.ts` を作成します:

```typescript theme={null}
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");
```

実行:

```bash theme={null}
bun run index.ts
```

<div id="scrape-a-page">
  ## ページをスクレイピングする
</div>

同じサーバーに `/scrape` ルートを追加します:

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

<div id="interact-with-a-page">
  ## Interact でページを操作する
</div>

Interact を使うと、ライブのブラウザセッションを操作して、ボタンのクリック、フォームへの入力、動的コンテンツの抽出を行えます。

```typescript theme={null}
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 });
}
```

<div id="script-usage">
  ## スクリプトでの使用
</div>

スタンドアロンのBunスクリプトでFirecrawlを使うには、次のようにします。

```typescript theme={null}
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);
```

```bash theme={null}
bun run search.ts
```

<div id="next-steps">
  ## 次のステップ
</div>

<CardGroup cols={2}>
  <Card title="スクレイピング ドキュメント" icon="file-lines" href="/ja/features/scrape">
    フォーマット、アクション、プロキシを含む、スクレイピングのオプション全般
  </Card>

  <Card title="Search ドキュメント" icon="magnifying-glass" href="/ja/features/search">
    Web を検索してページ全体のコンテンツを取得
  </Card>

  <Card title="Interact ドキュメント" icon="hand-pointer" href="/ja/features/interact">
    クリックやフォーム入力を行い、動的コンテンツを抽出
  </Card>

  <Card title="Node SDK リファレンス" icon="node" href="/ja/sdks/node">
    クロール、map、バッチスクレイプなどを含む SDK の完全なリファレンス
  </Card>
</CardGroup>
