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

prg-uploader

v0.1.1

Published

Node.js file upload utility

Downloads

6

Readme

Pragonauts Uploader

Busboy based utility, which helps us:

  1. Processes the multipart/form-data with busboy
  2. Validates uploads (mime type and size)
  3. Transforms each upload to a Promise (by default to Buffer)
  4. After all resolves promise

Example


const express = require('express');
const { Uploader, terminateStream } = require('prg-uploader');

const app = new express.Router();

app.post('/', (req, res) => {

    const uploader = new Uploader();

    uploader.addFile('image', terminateStream, '1mb', [
        'image/gif',
        'image/jpeg',
        'image/png'
    ]);

    uploader.process(req)
        .then((data) => {
            res.send({
                ok: 1,
                receivedMimeType: data.image.type,
                receivedFileSize; data.image.size, // same as buffer length
                receivedDataLength: data.image.data.length,
                isBuffer: Buffer.isBuffer(data.image.data) // true
            });
        })
        .catch((e) => {
            res.status(e.status) // 413=file size exceeded, 415=mime does not match
                .send(e.message);
        });
}));

module.exports = app;

Using with Pragonauts validator

Uploader uses validation rules from Validator and runs validator with given data


const express = require('express');
const Validator = require('prg-validator');
const { Uploader, terminateStream } = require('prg-uploader');

const app = new express.Router();


const validator = new Validator();

validator.add('file')
    .isFileMaxLength('shlould be smaller then 1Mb', '1m')
    .isFileMime('Should be an excel file', [
        'application/vnd.ms-excel',
        'application/msexcel',
        'application/x-msexcel',
        'application/x-ms-excel',
        'application/x-excel',
        'application/x-dos_ms_excel',
        'application/xls',
        'application/x-xls',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    ])
    .toFileData(); // extracts buffer from the file

app.post('/', (req, res) => {

    const uploader = new Uploader(validator);

    uploader.addFile('file');

    uploader.process(req)
        .then((data) => {
            res.send({
                ok: 1,
                receivedDataLength: data.file.length,
                isBuffer: Buffer.isBuffer(data.file) // true
            });
        })
        .catch((e) => {
            res.status(e.status) // 413=file size exceeded, 415=mime does not match
                .send(e.message);
        });
}));

module.exports = app;

API

Classes

Functions

Uploader

Kind: global class

new Uploader()

The NodeJs multipart/form-data processor

uploader.addFile(field, [processor], [maxLength], [allowedMimes]) ⇒ this

Add a file upload

Kind: instance method of Uploader

| Param | Type | Default | Description | | --- | --- | --- | --- | | field | string | | field name | | [processor] | function | terminateStream | the request processor | | [maxLength] | number | | size limit | | [allowedMimes] | Array.<string> | | accept only theese mime types (strings or RegExps) |

Example

// process upload on own using callback

uploader.addFile('fieldName', (stream, filename, encoding, mimetype) => {
    if (mimetype !== 'image/png') {
        stream.resume(); // call when stream is not used
        return Promise.resolve(null);
    }
    // process the stream and return Promise
    return Promise.resolve('the result of processing stream');
})

uploader.process(req, [validatorContext]) ⇒ Promise.<object>

Process the uploads

Kind: instance method of Uploader

| Param | Type | Default | Description | | --- | --- | --- | --- | | req | any | | the request | | [validatorContext] | string | null | the context to validator |

Uploader.Uploader

Kind: static class of Uploader

new Uploader([validator])

Creates an instance of Uploader.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [validator] | any | | instance of prg-validator |

LimitedStream ⇐ Transform

Kind: global class Extends: Transform

new LimitedStream()

Stream which throws error, when size of stream exceeds allowed length

Example

const stream = new LimitedStream({ maxLength: 1024 }); // 1Kb
stream.on('error', (err) => {
   if (err.code === 413) {
      // size exceeded
   }
});

LimitedStream.LimitedStream

Kind: static class of LimitedStream

new LimitedStream(options)

Creates an instance of LimitedStream.

| Param | Type | Description | | --- | --- | --- | | options | Object | | | [options.maxLength] | number | the maximal length in bytes |

terminateStream(readableStream) ⇒ Promise.<Buffer>

Converts a stream to buffer

Kind: global function

| Param | Type | | --- | --- | | readableStream | ReadableStream |