Description
A streaming and asynchronous multipart/form-data
parser.
Install
npm install form-parser --save
Examples
micro:
Using// Dependenciesconst parser = const send = // Create servermoduleexports = async { // Parse request await // Reply with finished return }
Native HTTP server:
// Dependenciesconst http = const parser = // Create serverconst server = http // Start serverserver
Streaming file upload:
// Dependenciesconst http = const parser = const path = const fs = // Create serverconst server = http // Start serverserver
API
parser(req, callback)
The parser()
function is a top-level function exported by the form-parser
module.
req
HTTP request object.callback(field => {})
An Async function, that's called for each new form field found. Passesfield
as argument.
field
Is an object containing the following keys:
fieldType
The field type (one of 'text' or 'file').fieldName
The field name.fieldContent
The field content.- If
fieldType
is 'text',fieldContent
will contain the field text value. - If
fieldType
is 'file',fieldContent
will contain an object with the following keys:fileName
The name of the file.fileType
The mime type of the file.fileStream
The file stream (ReadableStream).
- If