Express: download YouTube, TikTok and Instagram videos
Express is the most common place to wrap CrawlFetch for a frontend or mobile app: one route, one upstream call, and a response trimmed to what your clients need.
How it fits together
Your Express route receives a URL from your client, validates it, calls /v1/resolve with the server-side key and returns a small JSON payload. Errors from the API are mapped to friendly messages.
Express example
import express from "express";const router = express.Router();const MESSAGES = { 404: "This video is private or unavailable.", 429: "Too many requests, try again shortly." };router.get("/resolve", async (req, res) => {const url = String(req.query.url || "");if (!/^https?:\/\//.test(url)) return res.status(400).json({ message: "A video URL is required." });const r = await fetch("https://api.crawlfetch.com/v1/resolve?" + new URLSearchParams({ url }), {headers: { Authorization: "Bearer " + process.env.CRAWLFETCH_KEY },});if (!r.ok) return res.status(r.status).json({ message: MESSAGES[r.status] || "Could not resolve video." });const { title, thumbnail, downloadUrl, formats } = await r.json();res.json({ title, thumbnail, downloadUrl, formats });});export default router;
Notes for Express
- Mount it behind your auth middleware and a rate limiter such as
express-rate-limit. - Forward
Retry-Afteron 429 so clients know when to try again. - Wrap async handlers (or use Express 5) so rejected promises reach your error middleware.
FAQ
Should Express proxy the file itself?
Usually not — return downloadUrl and let the client download directly. Proxy only if you need to transform or store the file.
Does this work with Fastify or Koa?
Yes — the upstream call is identical; only the routing syntax changes.
Related
Last updated 2026-10-25