You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

formidable

Package Overview
Dependencies
Maintainers
5
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formidable

A node.js module for parsing form data, especially file uploads.

3.5.3
latest
npm
Version published
Weekly downloads
0
Maintainers
5
Weekly downloads
 
Created

What is formidable?

The formidable npm package is a Node.js module for parsing form data, especially file uploads. It can handle multipart/form-data, which is used for uploading files through forms.

What are formidable's main functionalities?

File Upload

This code creates an HTTP server that listens for POST requests on the '/upload' path. It uses formidable to parse the incoming form data and handle file uploads.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.parse(req, (err, fields, files) => {
      if (err) {
        res.writeHead(500, { 'content-type': 'text/plain' });
        res.end('Error parsing the files');
        return;
      }
      res.writeHead(200, { 'content-type': 'text/plain' });
      res.write('Files uploaded successfully:\n');
      res.end(JSON.stringify(files, null, 2));
    });
  }
}).listen(8080);

Form Field Parsing

This code snippet demonstrates how to use formidable to parse regular form fields (text inputs, selects, etc.) in addition to file uploads.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/submit' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.parse(req, (err, fields, files) => {
      if (err) {
        res.writeHead(500, { 'content-type': 'text/plain' });
        res.end('Error parsing the form fields');
        return;
      }
      res.writeHead(200, { 'content-type': 'text/plain' });
      res.write('Form fields submitted:\n');
      res.end(JSON.stringify(fields, null, 2));
    });
  }
}).listen(8080);

File Upload Progress

This example shows how to track the progress of a file upload using formidable's 'progress' event, which provides the bytes received and the total bytes expected.

const formidable = require('formidable');
const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
    const form = new formidable.IncomingForm();

    form.on('progress', (bytesReceived, bytesExpected) => {
      console.log(`Progress: ${bytesReceived}/${bytesExpected}`);
    });

    form.parse(req, (err, fields, files) => {
      // Handle file upload and response
    });
  }
}).listen(8080);

Other packages similar to formidable

Keywords

multipart

FAQs

Package last updated on 18 Apr 2025

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