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

@types/busboy

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/busboy

TypeScript definitions for busboy

  • 1.5.4
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
482K
increased by5.32%
Maintainers
1
Weekly downloads
 
Created

What is @types/busboy?

@types/busboy provides TypeScript definitions for the busboy package, which is a streaming parser for HTML form data for node.js. It is particularly useful for handling file uploads.

What are @types/busboy's main functionalities?

Parsing Form Data

This code demonstrates how to use busboy to parse form data, including file uploads, from an HTTP POST request.

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`);
      });
      file.on('end', () => {
        console.log(`File [${fieldname}] Finished`);
      });
    });
    busboy.on('field', (fieldname, val) => {
      console.log(`Field [${fieldname}]: value: ${val}`);
    });
    busboy.on('finish', () => {
      res.writeHead(200, { 'Connection': 'close' });
      res.end("That's all folks!");
    });
    req.pipe(busboy);
  } else {
    res.writeHead(404);
    res.end();
  }
}).listen(8000, () => {
  console.log('Listening for requests');
});

Handling File Uploads

This code demonstrates how to handle file uploads using busboy by saving the uploaded files to a specified directory.

const Busboy = require('busboy');
const fs = require('fs');
const path = require('path');
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) => {
      const saveTo = path.join(__dirname, 'uploads', path.basename(filename));
      file.pipe(fs.createWriteStream(saveTo));
    });
    busboy.on('finish', () => {
      res.writeHead(200, { 'Connection': 'close' });
      res.end('Upload complete');
    });
    req.pipe(busboy);
  } else {
    res.writeHead(404);
    res.end();
  }
}).listen(8000, () => {
  console.log('Listening for requests');
});

Other packages similar to @types/busboy

FAQs

Package last updated on 02 May 2024

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