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

> Utilisez Evocrawl avec NestJS pour créer des services de scraping web structuré et de recherche.

<div id="prerequisites">
  ## Prérequis
</div>

* Un projet NestJS (`@nestjs/cli`)
* Une clé API Evocrawl — [obtenez-en une gratuitement](https://www.evocrawl.com/app/api-keys)

<div id="install-the-sdk">
  ## Installer le SDK
</div>

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

Ajoutez votre clé API à `.env` :

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

<div id="create-a-evocrawl-service">
  ## Créer un service Evocrawl
</div>

Créez `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">
  ## Créer un contrôleur
</div>

Créez `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">
  ## Enregistrez le module
</div>

Créez `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 {}
```

Importez `EvocrawlModule` dans votre `AppModule`.

<div id="test-it">
  ## Essayez-le
</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">
  ## Étapes suivantes
</div>

<CardGroup cols={2}>
  <Card title="Documentation Scrape" icon="file-lines" href="/fr/features/scrape">
    Toutes les options de scrape, y compris les formats, les actions et les proxies
  </Card>

  <Card title="Documentation recherche" icon="magnifying-glass" href="/fr/features/search">
    Rechercher sur le web et obtenir le contenu complet des pages
  </Card>

  <Card title="Documentation Interact" icon="hand-pointer" href="/fr/features/interact">
    Cliquer, remplir des formulaires et extraire du contenu dynamique
  </Card>

  <Card title="Référence du SDK Node" icon="node" href="/fr/sdks/node">
    Référence complète du SDK avec crawl, cartographie, extraction par lot, etc.
  </Card>
</CardGroup>
