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

> Use Evocrawl with NestJS to build structured web scraping and search services.

## Prerequisites

* NestJS project (`@nestjs/cli`)
* A EvoCrawl API key — [get one free](https://www.evocrawl.com/app/api-keys)

## Install the SDK

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

Add your API key to `.env`:

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

## Create a Evocrawl service

Create `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;
  }
}
```

## Create a controller

Create `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);
  }
}
```

## Register the module

Create `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 {}
```

Import `EvocrawlModule` in your `AppModule`.

## Test it

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

## Next steps

<CardGroup cols={2}>
  <Card title="Scrape docs" icon="file-lines" href="/features/scrape">
    All scrape options including formats, actions, and proxies
  </Card>

  <Card title="Search docs" icon="magnifying-glass" href="/features/search">
    Search the web and get full page content
  </Card>

  <Card title="Interact docs" icon="hand-pointer" href="/features/interact">
    Click, fill forms, and extract dynamic content
  </Card>

  <Card title="Node SDK reference" icon="node" href="/sdks/node">
    Full SDK reference with crawl, map, batch scrape, and more
  </Card>
</CardGroup>
