> ## 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.

# Node.js

> 在 Node.js 中快速上手 Firecrawl。使用官方 SDK 抓取、搜索并与网页数据交互。

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

* Node.js 18+
* 一个 Firecrawl API 密钥——[免费获取](https://www.firecrawl.dev/app/api-keys)

<div id="install-the-sdk">
  ## 安装 SDK
</div>

```bash theme={null}
npm install firecrawl
```

<div id="environment-variable">
  ## 环境变量
</div>

不要直接传递 `apiKey`，请改为设置 `FIRECRAWL_API_KEY` 环境变量：

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

```javascript theme={null}
const app = new Firecrawl();
```

<div id="search-the-web">
  ## 进行网页搜索
</div>

```javascript theme={null}
import { Firecrawl } from 'firecrawl';

const app = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });
const results = await app.search("firecrawl web scraping", { limit: 5 });

for (const result of results.web) {
  console.log(result.title, result.url);
}
```

<div id="scrape-a-page">
  ## 抓取网页
</div>

```javascript theme={null}
const result = await app.scrape("https://example.com");

console.log(result.markdown);
```

<Accordion title="示例响应">
  ```json theme={null}
  {
    "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
    "metadata": {
      "title": "Example Domain",
      "sourceURL": "https://example.com"
    }
  }
  ```
</Accordion>

<div id="interact-with-a-page">
  ## 与页面交互
</div>

使用 `interact` 控制实时浏览器会话——点击按钮、填写表单，并提取动态内容。

```javascript theme={null}
const result = await app.scrape('https://www.amazon.com', { formats: ['markdown'] });
const scrapeId = result.metadata?.scrapeId;

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

await app.stopInteraction(scrapeId);
```

<div id="next-steps">
  ## 下一步
</div>

<CardGroup cols={2}>
  <Card title="抓取文档" icon="file-lines" href="/zh/features/scrape">
    包含所有 scrape 选项，包括 formats、actions 和代理
  </Card>

  <Card title="搜索文档" icon="magnifying-glass" href="/zh/features/search">
    进行网页搜索并获取完整页面内容
  </Card>

  <Card title="交互文档" icon="hand-pointer" href="/zh/features/interact">
    点击、填写表单并提取动态内容
  </Card>

  <Card title="Node SDK 参考文档" icon="node" href="/zh/sdks/node">
    完整的 SDK 参考，涵盖爬取、map、batch scrape 等功能
  </Card>
</CardGroup>
