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 🙏

© 2025 – Pkg Stats / Ryan Hefner

file-streamer

v1.2.0

Published

A TypeScript package for streaming data as files (Excel, CSV, JSON, Base64) and streaming files from file system through HTTP responses

Readme

file-streamer

A developer-friendly NPM package for streaming files directly over HTTP, reducing server load and optimizing performance for large data transfers.

Description

file-streamer is a TypeScript package that enables efficient, real-time streaming of files directly to HTTP responses. By sending data as a stream instead of a single payload, it helps developers handle large data exports with minimal memory usage and improved server reliability. With a simple, one-line integration, it abstracts away the streaming logic, making large file delivery seamless and greatly enhancing developer experience.

Key Features

  • Streaming Data: Efficiently stream data to HTTP responses, reducing memory usage.
  • Multiple File Types: Supports Excel (xlsx), CSV, JSON, file, base64 formats currently.
  • Express.js Integration: Designed to work seamlessly with Express.js.
  • TypeScript Support: Fully written in TypeScript for type safety and improved developer experience.

Installation

Install the package using npm:

npm install file-streamer

Usage

Backend

Here's a basic example of how to use file-streamer with Express.js:

import { pipeJsonAsExcel } from 'file-streamer';

// Dummy data for Excel export
const dummyData = [
  {
    'Employee ID': 'EMP001',
    'First Name': 'John',
    'Last Name': 'Doe',
    Email: '[email protected]',
    Department: 'Engineering',
    Salary: 75000,
    'Hire Date': '2023-01-15',
    Status: 'Active'
  },
  {
    'Employee ID': 'EMP002',
    'First Name': 'Jane',
    'Last Name': 'Smith',
    Email: '[email protected]',
    Department: 'Marketing',
    Salary: 65000,
    'Hire Date': '2023-03-20',
    Status: 'Active'
  }
];

export const downloadRoute = async (req, res) => {
  try {
    // Get optional filename from query parameters
    const fileName = req.query.filename || 'employee_data';

    // Use the file-streamer package to convert JSON to Excel and pipe it as response
    await pipeJsonAsExcel(res, dummyData, fileName); // Just one line and you're all set!
  } catch (error) {
    console.error('Error generating Excel file:', error);
    res.status(500).json({
      error: 'Failed to generate Excel file',
      message: error.message
    });
  }
};

Frontend

You're probably going to use this for downloading a file onto user's machine, here's the code to handle the streaming response!

<button
  onClick={async () => {
    const response = await axios.get('http://localhost:3000/api/download/csv', {
      responseType: 'blob'
    });

    const url = window.URL.createObjectURL(response.data);
    const a = document.createElement('a');
    a.href = url;
    a.download = `file.csv`;
    a.click();
  }}
>
  Download JSON AS CSV
</button>

Features

| Function | Parameters | Description | | ------------------ | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- | | pipeJsonAsExcel | res: express.Response, jsonData: any, filename?: string | Pipes JSON data to an Excel file and streams it as an HTTP response. | | pipeJsonAsCsv | res: express.Response, jsonData: any, filename?: string | Pipes JSON data to a CSV string and streams it as an HTTP response. | | pipeJsonAsJson | res: express.Response, jsonData: any, filename?: string | Pipes JSON data to a JSON string and streams it as an HTTP response. | | pipeBase64 | res: express.Response, base64Data: string, contentType?: string, filename?: string | Pipes base64 data to a file and streams it as an HTTP response. | | pipeFileFromPath | res: express.Response, filePath: string, fileName?: string, contentType?: string | Pipes a file from the file system and streams it as an HTTP response. |

Contributing

Contributions are welcome! Please follow these steps:

  1. Raise an issue/feature request and get assigned to it.
  2. Fork the repository.
  3. Create a new branch for your feature or bug fix.
  4. Make your changes and ensure they are well-tested.
  5. Submit a pull request with a clear description of your changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.