Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

busboy

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

busboy

A streaming parser for HTML form data for node.js

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is busboy?

The busboy npm package is a Node.js module for parsing incoming HTML form data, particularly file uploads. It is a stream-based parser that can handle multipart/form-data, which is primarily used for uploading files via HTTP.

What are busboy's main functionalities?

File Upload Parsing

This code sample demonstrates how to use busboy to parse file uploads from an HTML form. When a file is received, it logs the file details and the amount of data received.

const Busboy = require('busboy');
const http = require('http');

http.createServer((req, res) => {
  if (req.method === 'POST') {
    const busboy = new Busboy({ headers: req.headers });
    busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
      console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);
      file.on('data', (data) => {
        console.log(`File [${fieldname}] got ${data.length} bytes`);
      }).on('end', () => {
        console.log(`File [${fieldname}] Finished`);
      });
    });
    busboy.on('finish', () => {
      console.log('Done parsing form!');
      res.writeHead(303, { Connection: 'close', Location: '/' });
      res.end();
    });
    req.pipe(busboy);
  } else {
    res.writeHead(404);
    res.end();
  }
}).listen(8000, () => {
  console.log('Server listening on port 8000');
});

Field Parsing

This code sample shows how to use busboy to parse non-file fields from an HTML form. It logs the name and value of each field received.

const Busboy = require('busboy');
const http = require('http');

http.createServer((req, res) => {
  if (req.method === 'POST') {
    const busboy = new Busboy({ headers: req.headers });
    busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
      console.log(`Field [${fieldname}]: value: ${val}`);
    });
    busboy.on('finish', () => {
      res.end('Done parsing form!');
    });
    req.pipe(busboy);
  } else {
    res.writeHead(404);
    res.end();
  }
}).listen(8000, () => {
  console.log('Server listening on port 8000');
});

Other packages similar to busboy

Keywords

FAQs

Package last updated on 01 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc