
Why I Stopped Writing Video Files to Disk and Route Everything Through /tmp
When I built the first version of dltkk.to I made the obvious choice — download the video file, save it to a downloads folder, stream it to the user, clean up on a timer. Within a week I had three problems: Disk filling up when cleanup timers misfired on server restarts Stale files from failed downloads accumulating Potential privacy issue if a user's file sat on disk longer than it should Here's how I fixed all three by routing everything through /tmp . The Original Architecture (Wrong) // Old approach — save to disk, cleanup later const outputDir = ' ./downloads ' ; const filename = `video_ ${ Date . now ()} .mp4` ; const outputPath = path . join ( outputDir , filename ); const ytdlp = spawn ( ' yt-dlp ' , [ ' -o ' , outputPath , url ]); ytdlp . on ( ' close ' , ( code ) => { res . download ( outputPath , () => { fs . unlinkSync ( outputPath ); // What if this fails? }); }); // Cleanup timer as fallback setInterval (() => { // Delete files older than 10 minutes // But what if server
Continue reading on Dev.to Webdev
Opens in a new tab




