crawlfetch

NestJS: download YouTube, TikTok and Instagram videos

In NestJS, wrap CrawlFetch in an injectable service so controllers, queues and cron jobs share one configured client.

How it fits together

A CrawlFetchService reads the key from ConfigService, calls the API with HttpService (Axios), and throws Nest exceptions that map cleanly to HTTP responses.

NestJS example

import { HttpService } from "@nestjs/axios";
import { HttpException, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { firstValueFrom } from "rxjs";
@Injectable()
export class CrawlFetchService {
constructor(private http: HttpService, private config: ConfigService) {}
async resolve(url: string) {
try {
const { data } = await firstValueFrom(
this.http.get("https://api.crawlfetch.com/v1/resolve", {
params: { url },
headers: { Authorization: "Bearer " + this.config.getOrThrow("CRAWLFETCH_KEY") },
timeout: 15_000,
}),
);
return data;
} catch (err: any) {
throw new HttpException("Could not resolve video", err.response?.status ?? 502);
}
}
}

Notes for NestJS

  • Register HttpModule and ConfigModule in the feature module.
  • Use @nestjs/bullmq to run bulk downloads as background jobs.
  • Add @nestjs/throttler to public endpoints that call the service.

FAQ

Can I use native fetch instead of HttpService?

Yes. HttpService is optional; any HTTP client works.

Related

Last updated 2026-10-25

Add video downloads to your product today.

1,000 credits on signup plus 500 every month. That is roughly 180 YouTube clips to start, with no card.

Create free account