Lesson 32 / 34

Streaming & Large Responses

Stream large files and responses with StreamableFile instead of loading them into memory.

Stream a file

Use StreamableFile or Express' response object to stream large files without loading into memory.

import { StreamableFile } from '@nestjs/common';
import { createReadStream } from 'fs';

@Get('download')
downloadFile(): StreamableFile {
  const file = createReadStream('large-file.zip');
  return new StreamableFile(file);
}