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

omulti

v0.0.17

Published

Node.js HTTP file uploads

Readme

Omulti - Node.js HTTP file uploads

tests

Getting started

Omulti is a Node.js library that handles HTTP file uploads.

  • Fast
  • Easy to use
  • Written in Typescript
  • It has very few dependencies

To install it run:

npm i omulti

How to use it

Basic usage with Node.js HTTP server

To use it with a Node.js HTTP server simply create a new HTTP server an pass the request object into the Omulti constructor like so:

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    for await (const file of omulti.getFiles()) {
        await file.saveToDisk("/path/where/to/save/file");
    }
});

httpServer.listen(3000);

As you can see the omulti.getFiles() function returns an async generator that allows you to iterate over evey file.

Alternatively, you can also use events if you want:

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    omulti.on("file", (file) => {
        console.log(file.filename);
    });
});

httpServer.listen(3000);

Since Omulti handles multipart/form-data this means that besides files we might also receive input data from form fields.

To get just the fields do:

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    for await (const field of omulti.getFields()) {
        console.log(field.name);
    }
});

httpServer.listen(3000);

To get both files and fields you can use the getAll() method. However you need to distinguish between these two types when working with them:

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    for await (const part of omulti.getAll()) {
        if (part.isFile()) {
            // it's a file
        } else {
            // it's a field
        }
    }
});

httpServer.listen(3000);

As before you can use events here instead, so to get the fields listen on the field event.

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    omulti.on("field", (field) => {
        console.log(file.name);
    });
});

httpServer.listen(3000);

Or to get both files and fields, use the part event:

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);

    omulti.on("part", (part) => {
        if (part.isFile()) {
            // it's a file
        } else {
            // it's a field
        }
    });
});

httpServer.listen(3000);

Options

Omulti allows several options to be passed to the constructor when creating a new instance. All the options are optional.

const omulti = new Omulti(req, {
    maxTotalSize: Number,
    maxFileSize: Number,
    maxFieldSize: Number,
    maxNumberOfFiles: Number,
    maxNumberOfFields: Number,
    maxBufferSize: Number,
});

| Option | Description | Default | | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | maxTotalSize | Represents the maximum number of bytes allowed for the entire request | Infinity | | maxFileSize | Represents the maximum number of bytes allowed per file | Infinity | | maxFieldSize | Represents the maximum number of bytes allowed per field | Infinity | | maxNumberOfFiles | Represents the maximum number of files allowed per request | Infinity | | maxNumberOfFields | Represents the maximum number of fields allowed per request | Infinity | | maxBufferSize | Represents the maximum allowed number of bytes to use for the internal buffer. Caution This value is required for Omulti in order to function properly, so it's best not to change it. | 10MB |

Files and Fields

Properties

A Field has the following properties:

  • name: string | undefined
  • contentType: string | undefined

and a File has the same properties plus:

  • filename: string | undefined

Both entities have a stream property that is a Readable stream.

E.g. you can use this to pipe to a writable stream:

import { createWriteStream } from "fs";
import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req);
    for await (const file of omulti.getFiles()) {
        const writeStream = createWriteStream("/some/path/to/a/dir");
        file.stream.pipe(writeStream);
    }
});

httpServer.listen(3000);

Methods

Field

  • getContents()

File

  • getContents()
  • saveToDisk(path: string)

getContents()

Both entities have a getContents() method that returns a Promise<Buffer> with the entire contents of the Field/File. Be careful when using this, make sure to explicitly set the maxFieldSize and/or the maxFileSize, to prevent the host machine from being starved of memory.

import { createServer } from "http";
import { Omulti } from "omulti";

const httpServer = createServer(async (req, res) => {
    const omulti = new Omulti(req, {
        maxFileSize: 2 * 1024 * 1024, /// max 2MB
    });
    for await (const file of omulti.getFiles()) {
        const contents = (await file.getContents()).toString("utf-8");
        /// do something with the contents
    }
});

httpServer.listen(3000);

saveToDisk(path: string)

The File object also has a saveToDisk('path/to/save/file') method that will save the file to a provided path on the disk.