{"versions":{"0.1.0":{"name":"form-parser","version":"0.1.0","description":"A streaming and asynchronous multipart/form-data parser.","main":"index.js","keywords":["uploads","forms","post","multipart","form-data","formdata","streams"],"author":{"name":"Kasper Neist","email":"kasper@neist.com"},"license":"MIT","dependencies":{"busboy":"^0.2.14"},"gitHead":"5d6cd780bffb2c6c2b45ed01c00836fffafc2dbc","_id":"form-parser@0.1.0","_npmVersion":"5.8.0","_nodeVersion":"9.8.0","_npmUser":{"name":"anonymous","email":"kasper@astonish.dk"},"dist":{"integrity":"sha512-wcjPVJ0VyGqE4fJ1JGutwb/qIwKRMfyXK3nckEAxoNS35pSaY+CmCD/M3jnyeb9/E3AlYm0oA/9D0VKAh6W/Jw==","shasum":"87833cc41f79d8481d3cdbfa7cf8b5ffebc27ee9","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/form-parser/-/form-parser-0.1.0.tgz","fileCount":3,"unpackedSize":5571,"size":1884},"maintainers":[{"name":"anonymous","email":"kasper@astonish.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/form-parser_0.1.0_1522506785218_0.7986223051027692"},"_cnpmcore_publish_time":"2021-12-23T10:31:02.221Z","contributors":[]},"0.1.1":{"name":"form-parser","version":"0.1.1","description":"A streaming and asynchronous multipart/form-data parser.","main":"index.js","keywords":["uploads","forms","post","multipart","form-data","formdata","streams"],"author":{"name":"Kasper Neist","email":"kasper@neist.com"},"bugs":{"url":"https://github.com/neist/form-parser/issues"},"repository":{"type":"git","url":"git+https://github.com/neist/form-parser.git"},"homepage":"https://github.com/neist/form-parser/","license":"MIT","dependencies":{"busboy":"^0.2.14"},"gitHead":"32398ee5bc343d32eace766c0ceafbbd2a5a7778","_id":"form-parser@0.1.1","_npmVersion":"5.8.0","_nodeVersion":"9.8.0","_npmUser":{"name":"anonymous","email":"kasper@astonish.dk"},"dist":{"integrity":"sha512-+WgwcJXWrqGRt2s9fdkXzCJonrOCp92qDPndLyVJQiCeNjLFNkE6Tt8oCftvl3inP5Jg0LBs0H2SYrf8b6IMbA==","shasum":"fc4c3bf1c3223036d1ebedf0e205a31669c80d26","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/form-parser/-/form-parser-0.1.1.tgz","fileCount":3,"unpackedSize":6105,"size":2048},"maintainers":[{"name":"anonymous","email":"kasper@astonish.dk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/form-parser_0.1.1_1522521361909_0.17185470768704092"},"_cnpmcore_publish_time":"2021-12-23T10:31:03.098Z","contributors":[]}},"dist-tags":{"latest":"0.1.1"},"name":"form-parser","time":{"created":"2022-01-27T02:11:39.395Z","modified":"2022-01-27T02:11:39.395Z","0.1.0":"2018-03-31T14:33:05.322Z","0.1.1":"2018-03-31T18:36:02.011Z"},"readme":"# Description\nA streaming and asynchronous `multipart/form-data` parser.\n\n# Install\n```bash\nnpm install form-parser --save\n```\n\n# Examples\n\n## Using [micro](https://github.com/zeit/micro):\n```js\n// Dependencies\nconst parser = require('form-parser')\nconst { send } = require('micro')\n\n// Create server\nmodule.exports = async (req, res) => {\n  // Parse request\n  await parser(req, async field => {\n    // Log info\n    console.log(field) // { fieldType, fieldName, fieldContent }\n  })\n\n  // Reply with finished\n  return send(res, 200, 'Parsing form succeded.')\n}\n```\n\n## Native HTTP server:\n```js\n// Dependencies\nconst http = require('http')\nconst parser = require('form-parser')\n\n// Create server\nconst server = http.createServer(async (req, res) => {\n  // Wrap in try/catch block\n  try {\n    // Parse request\n    await parser(req, async field => {\n      // Log info\n      console.log(field) // { fieldType, fieldName, fieldContent }\n    })\n  \n  // Catch errors\n  } catch (err) {\n    // Log error\n    console.error(err)\n\n    // Reply with error\n    res.statusCode = 400\n    return res.end('Something went wrong.')\n  }\n\n  // Reply with success\n  return res.end('Parsing form succeded.')\n})\n\n// Start server\nserver.listen(3000, () => {\n  console.log('Listening on port 3000...')\n})\n```\n\n## Streaming file upload:\n```js\n// Dependencies\nconst http = require('http')\nconst parser = require('form-parser')\nconst path = require('path')\nconst fs = require('fs')\n\n// Create server\nconst server = http.createServer(async (req, res) => {\n  try {\n    // Parse request\n    await parser(req, async field => {\n      // Get info\n      const { fieldType, fieldName, fieldContent } = field\n      \n      // Only handle files\n      if (fieldType !== 'file') {\n        return\n      }\n\n      // Get file info\n      const { fileName, fileType, fileStream } = fieldContent\n\n      // Prepare write stream\n      const writeFilePath = path.resolve(__dirname, 'files', fileName)\n      const writeFileStream = fs.createWriteStream(writeFilePath)\n\n      // Write file to disk\n      await new Promise((resolve, reject) => {\n        fileStream.pipe(writeFileStream).on('error', reject).on('finish', resolve)\n      })\n\n      // Log info\n      console.log(`${fileName} has been written to disk.`)\n    })\n  \n  // Catch errors\n  } catch (err) {\n    // Log error\n    console.error(err)\n\n    // Reply with error\n    res.statusCode = 400\n    return res.end('Something went wrong.')\n  }\n\n  // Reply with success\n  return res.end('Parsing form succeded.')\n})\n\n// Start server\nserver.listen(3000, () => {\n  console.log('Listening on port 3000...')\n})\n```\n\n# API\n\n## `parser(req, callback)`\nThe `parser()` function is a top-level function exported by the `form-parser` module.\n\n* `req` HTTP request object.\n* `callback(field => {})` An Async function, that's called for each new form field found. Passes `field` as argument.\n\n`field` Is an object containing the following keys:\n  * `fieldType` The field type (one of 'text' or 'file').\n  * `fieldName` The field name.\n  * `fieldContent` The field content.\n    * If `fieldType` is 'text', `fieldContent` will contain the field text value.\n    * If `fieldType` is 'file', `fieldContent` will contain an object with the following keys:\n      * `fileName` The name of the file.\n      * `fileType` The mime type of the file.\n      * `fileStream` The file stream (ReadableStream).","users":{}}