TLDR Web Dev · ARTICLES & TUTORIALS
HOW TO STREAM FILES FROM NEXT.JS ROUTE HANDLERS
Summary from the TLDR Web Dev newsletter
We traditionally use a "public" folder to serve files in Node.js applications. However, this only works for static assets and doesn’t work for files like profile pictures, private files, or generated files - these files are served from an API and loaded into memory. This isn’t scalable when there are a lot of users. Instead, it’s useful to use a stream to return large files in chunks. This article looks at a couple of ways to achieve this using both Next.js API routes and also the more generic Route handlers.