busboy
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
streamsearch | 1.1.0 | 5.24 kB | MIT | prod |
Busboy is a powerful node.js module designed for parsing incoming HTML form data. This popular npm package allows developers to efficiently handle HTML form data, providing a streaming parser that proves highly beneficial in web development scenarios where form data needs to be parsed on the server side. By harnessing the power of streams, Busboy efficiently parses incoming HTTP requests that contain form data without sacrificing memory overhead.
To use Busboy in your node.js application, start by installing the package using npm. You can do this by running npm install busboy
from your project's root directory. After successfully installing Busboy, you can use it to parse incoming HTML form data with Node.js' HTTP module. Below are two basic usage examples:
Example 1: Parsing multipart form data with default options.
const http = require('http');
const busboy = require('busboy');
http.createServer((req, res) => {
if (req.method === 'POST') {
const bb = busboy({ headers: req.headers });
// Bind event handlers to bb...
req.pipe(bb);
}
// Handle GET requests...
}).listen(8000);
Example 2: Save all incoming files to disk
const http = require('http');
const busboy = require('busboy');
http.createServer((req, res) => {
if (req.method === 'POST') {
const bb = busboy({ headers: req.headers });
bb.on('file', (name, file, info) => {
file.pipe(fs.createWriteStream(`path/to/save/${name}`));
});
req.pipe(bb);
}
// Handle other HTTP methods...
}).listen(8000);
Please note, you must pipe the request stream into Busboy's form parser stream, and handle every incoming file and field using respective event handlers. Don't forget to listen for 'POST' requests before initiating the parser.
The most comprehensive documentation for Busboy can be found directly in Busboy's GitHub repository. Here, you will find detailed information about the Busboy API, including example code snippets, configuration options for the parser, and various event handlers that the library provides. Additionally, this documentation dives into the configurable limits of incoming data and the special parser stream events that can be used to handle form parsing events like file uploads or fields limit reached. The API section carefully explains all the interfaces and events provided by the Busboy.