Skip to main content

Prerequisites

  • NestJS project (@nestjs/cli)
  • A Evocrawl API key — get one free

Install the SDK

npm install @mendable/firecrawl-js
Add your API key to .env:
FIRECRAWL_API_KEY=fc-YOUR-API-KEY

Create a Evocrawl service

Create src/firecrawl/firecrawl.service.ts:
import { Injectable } from "@nestjs/common";
import Evocrawl from "@mendable/firecrawl-js";

@Injectable()
export class EvocrawlService {
  private readonly client: Evocrawl;

  constructor() {
    this.client = new Evocrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
  }

  async search(query: string, limit = 5) {
    return this.client.search(query, { limit });
  }

  async scrape(url: string) {
    return this.client.scrape(url);
  }

  async interact(url: string, prompts: string[]) {
    const result = await this.client.scrape(url, { formats: ['markdown'] });
    const scrapeId = result.metadata?.scrapeId;

    const responses = [];
    for (const prompt of prompts) {
      const response = await this.client.interact(scrapeId, { prompt });
      responses.push(response);
    }

    await this.client.stopInteraction(scrapeId);
    return responses;
  }
}

Create a controller

Create src/firecrawl/firecrawl.controller.ts:
import { Body, Controller, Post } from "@nestjs/common";
import { EvocrawlService } from "./firecrawl.service";

@Controller("firecrawl")
export class EvocrawlController {
  constructor(private readonly firecrawlService: EvocrawlService) {}

  @Post("search")
  async search(@Body("query") query: string) {
    return this.firecrawlService.search(query);
  }

  @Post("scrape")
  async scrape(@Body("url") url: string) {
    return this.firecrawlService.scrape(url);
  }

  @Post("interact")
  async interact(@Body("url") url: string, @Body("prompts") prompts: string[]) {
    return this.firecrawlService.interact(url, prompts);
  }
}

Register the module

Create src/firecrawl/firecrawl.module.ts:
import { Module } from "@nestjs/common";
import { EvocrawlService } from "./firecrawl.service";
import { EvocrawlController } from "./firecrawl.controller";

@Module({
  providers: [EvocrawlService],
  controllers: [EvocrawlController],
  exports: [EvocrawlService],
})
export class EvocrawlModule {}
Import EvocrawlModule in your AppModule.

Test it

curl -X POST http://localhost:3000/firecrawl/search \
  -H "Content-Type: application/json" \
  -d '{"query": "firecrawl web scraping"}'

Next steps

Scrape docs

All scrape options including formats, actions, and proxies

Search docs

Search the web and get full page content

Interact docs

Click, fill forms, and extract dynamic content

Node SDK reference

Full SDK reference with crawl, map, batch scrape, and more