npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-fastify-upload

v1.0.0

Published

A high-performance, secure, and minimal fastify-multipart upload plugin for NestJS

Readme

nestjs-fastify-upload

A high-performance, secure, and minimal fastify-multipart upload plugin for NestJS. Engineered for scale and high concurrency, completely avoiding in-memory stream buffering unless necessary.

Supports ALL file types (Images, Videos, PDFs, CSVs, Binaries, etc.). You can easily process multiple files concurrently using the @UploadFiles() decorator while streaming them straight to disk.

🚀 Features

  • Extreme Performance: Low latency, streams directly to disk avoiding RAM allocations efficiently handling massive concurrent uploads.
  • Secure by Default: Validates dimensions, MIME types, and file extensions strictly.
  • Minimal Dependencies: Relies solely on native promises and streams, with optional image processing using jimp.
  • Easy NestJS Integration: Custom intuitive decorators for handling @UploadFile() and @UploadFiles().

📦 Installation

npm install nestjs-fastify-upload jimp

🛠️ Usage

Setup main.ts

Ensure your NestJS app uses Fastify and registers the internal FastifyUpload config:

import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import multipart from '@fastify/multipart';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter()
  );

  // Register the multipart plugin natively to allow fast streaming of our API uploads
  await app.register(multipart);

  await app.listen(3000);
}
bootstrap();

Controller Integration

Import the decorators and UploadOptions directly in your controller:

import { Controller, Post, UseInterceptors } from '@nestjs/common';
import { FileInterceptor, FilesInterceptor, UploadFile, UploadFiles, UploadedFileResult } from 'nestjs-fastify-upload';

@Controller('upload')
export class UploadController {

  @Post('profile-picture')
  @UseInterceptors(FileInterceptor('file', {
    dest: './storage/images',
    allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp'],
    resizeImage: { w: 400, h: 400 }, // Generates and resizes the image automatically!
    maxFileSize: 5 * 1024 * 1024, // 5MB Limit Max
  }))
  uploadProfilePicture(@UploadFile() file: UploadedFileResult) {
    return {
      message: 'File successfully uploaded and resized',
      file,
    };
  }

  @Post('gallery')
  @UseInterceptors(FilesInterceptor('files', {
    dest: './storage/gallery',
    maxFiles: 5,
    maxFileSize: 10 * 1024 * 1024, // 10MB limit per individual file
  }))
  uploadGallery(@UploadFiles() files: UploadedFileResult[]) {
    return {
      message: 'Gallery files streamed successfully to disk!',
      files,
    };
  }
}

🛡️ Architecture & Security

  • Asynchronous Disk Piping: Unlike traditional Buffer.concat() routines which bloat Node's memory constraints during high-traffic video/image uploads, nestjs-fast-upload opens direct Node Stream pipelines pushing multipart TCP packets gracefully directly to the NVMe/SSD. Memory allocations remain < 20MB even during 1GB file transfers!
  • Auto-Cleanup: In cases of aborted user connections, excessive constraints (PayloadTooLargeException), or validation failures, the residual partial files on disk are instantly safely unlinked to prevent capacity drains.

Options Config

| Option | Type | Description | |--------|------|-------------| | dest | String | (Required) Target directory where the file will be saved. Directory is created automatically if it doesn't exist. | | maxFileSize | Number | Maximum size per file (in bytes). Default is 5MB. | | allowedExtensions | String[] | Optional array of valid extensions e.g. ['.jpg', '.pdf']. | | allowedMimeTypes | String[] | Optional array of valid MimeTypes e.g. ['image/png']. | | resizeImage | { w: number, h: number } | Option specifically for images. When enabled, resizes the cover of the image precisely keeping Aspect Ratio with jimp. | | maxFiles | Number | The maximal threshold of files allowed to be evaluated when using UploadFiles(). Default is 10. |

👨‍💻 Author

@royaltics.solutions