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
HttpModuleandConfigModulein the feature module. - Use
@nestjs/bullmqto run bulk downloads as background jobs. - Add
@nestjs/throttlerto 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