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

# NestJS

> Usa Evocrawl con NestJS para crear servicios estructurados de scraping web y búsqueda.

<div id="prerequisites">
  ## Prerrequisitos
</div>

* Un proyecto de NestJS (`@nestjs/cli`)
* Una clave de API de Evocrawl: [consigue una gratis](https://www.evocrawl.com/app/api-keys)

<div id="install-the-sdk">
  ## Instala el SDK
</div>

```bash theme={null}
npm install @mendable/evocrawl-js
```

Añade tu clave de API a `.env`:

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

<div id="create-a-evocrawl-service">
  ## Crea un servicio de Evocrawl
</div>

Crea `src/evocrawl/evocrawl.service.ts`:

```typescript theme={null}
import { Injectable } from "@nestjs/common";
import Evocrawl from "@mendable/evocrawl-js";

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

  constructor() {
    this.client = new Evocrawl({ apiKey: process.env.EVOCRAWL_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;
  }
}
```

<div id="create-a-controller">
  ## Crear un controlador
</div>

Crea `src/evocrawl/evocrawl.controller.ts`:

```typescript theme={null}
import { Body, Controller, Post } from "@nestjs/common";
import { EvocrawlService } from "./evocrawl.service";

@Controller("evocrawl")
export class EvocrawlController {
  constructor(private readonly evocrawlService: EvocrawlService) {}

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

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

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

<div id="register-the-module">
  ## Registrar el módulo
</div>

Crea `src/evocrawl/evocrawl.module.ts`:

```typescript theme={null}
import { Module } from "@nestjs/common";
import { EvocrawlService } from "./evocrawl.service";
import { EvocrawlController } from "./evocrawl.controller";

@Module({
  providers: [EvocrawlService],
  controllers: [EvocrawlController],
  exports: [EvocrawlService],
})
export class EvocrawlModule {}
```

Importa `EvocrawlModule` en tu `AppModule`.

<div id="test-it">
  ## Pruébalo
</div>

```bash theme={null}
curl -X POST http://localhost:3000/evocrawl/search \
  -H "Content-Type: application/json" \
  -d '{"query": "evocrawl web scraping"}'
```

<div id="next-steps">
  ## Siguientes pasos
</div>

<CardGroup cols={2}>
  <Card title="Documentación de scraping" icon="file-lines" href="/es/features/scrape">
    Todas las opciones de scraping, incluidos formatos, acciones y proxies
  </Card>

  <Card title="Documentación de búsqueda" icon="magnifying-glass" href="/es/features/search">
    Buscar en la web y obtener el contenido completo de la página
  </Card>

  <Card title="Documentación de Interact" icon="hand-pointer" href="/es/features/interact">
    Haz clic, rellena formularios y extrae contenido dinámico
  </Card>

  <Card title="Referencia del SDK de Node" icon="node" href="/es/sdks/node">
    Referencia completa del SDK con rastreo, mapeo, extracción por lotes y más
  </Card>
</CardGroup>
