
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
@types/formidable
Advanced tools
TypeScript definitions for formidable
@types/formidable provides TypeScript type definitions for the formidable package, which is used for parsing form data, especially file uploads.
Parsing Form Data
This feature allows you to parse incoming form data, including file uploads. The `form.parse` method takes a request object and a callback function that handles the parsed fields and files.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Fields:', fields);
console.log('Files:', files);
});
Handling File Uploads
This feature allows you to handle file uploads by specifying an upload directory. The `uploadDir` property sets the directory where uploaded files will be stored.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.uploadDir = '/path/to/upload/directory';
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Uploaded files:', files);
});
Customizing File Uploads
This feature allows you to customize the file upload process. The `fileBegin` event is triggered when a file upload starts, allowing you to set a custom file path.
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.on('fileBegin', (name, file) => {
file.path = '/custom/path/' + file.name;
});
form.parse(req, (err, fields, files) => {
if (err) {
console.error(err);
return;
}
console.log('Custom file path:', files);
});
Multer is a middleware for handling `multipart/form-data`, which is primarily used for uploading files. It is similar to formidable but is designed to work specifically with Express.js. Multer is more modern and integrates seamlessly with Express, making it a popular choice for file uploads in Express applications.
Busboy is a fast and low-level library for parsing `multipart/form-data` used for file uploads. It is similar to formidable but offers more control and is more performant. Busboy is often used in scenarios where performance is critical and fine-grained control over file uploads is required.
Multiparty is another library for parsing `multipart/form-data`, similar to formidable. It is known for its simplicity and ease of use. Multiparty is a good alternative if you need a straightforward solution for handling file uploads without the additional features provided by formidable.
npm install --save @types/formidable
This package contains type definitions for formidable (https://github.com/node-formidable/formidable).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/formidable.
These definitions were written by Wim Looman, Martin Badin, and devLana.
FAQs
TypeScript definitions for formidable
The npm package @types/formidable receives a total of 521,635 weekly downloads. As such, @types/formidable popularity was classified as popular.
We found that @types/formidable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.