easy-formdata
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

easy-formdata

easy-formdata is a module to parse form data easily

Usage

const { expressParser, isFile } = require("easy-formdata");
const express = require("express");
const app = express();
 
app.use(expressParser());
 
app.post("/api", ({ body }, res) => {
  for(const key in body){
    if(isFile(body[key]))
      console.log(`${key} is ${body[key].size} bytes file`);
    else
      console.log(`${key} is a text field`);  
  }
  res.send(body);
})
 
app.listen(4000, () => console.log("server started"));

Types

expressParser

is the middleware that parsers the formdata for express

isFile

returns true if the argument passed is a File Object

File

an interface having this properties

  interface File {
    /** the file name */
    filename: string;
    /** the encoding of the file  */
    encoding: string;
    /** the mimetype of the file */
    mimetype: string;
    /** the size of the file */
    size: number;
    /** the data of the file */
    data: Buffer;
  }

Readme

Keywords

none

Package Sidebar

Install

npm i easy-formdata

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

3.33 kB

Total Files

6

Last publish

Collaborators

  • ali_ahmed