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

0.2.2 • Public • Published

formbody

formbody is a node.js middleware to handle multipart/form-data, typescript friendly.

Installation

npm i formbody

Useabe

typescript example

import { formbody } from 'formbody';

// ...

app.use(formbody);

app.all('/', (req: Request, res: Response) => {
  console.log(req.form.body);
  console.log(req.form.file('file'));
  console.log(req.form.get('name'));
  console.log(req.form.has('name'));

  // NOTE: this select will not return file type value
  console.log(req.form.select(['name', 'file']));

  res.sendStatus(200);
});

Interfaces

interface FormbodyFile {
  buffer: Buffer;
  filename: string;
  size?: number;
  mimetype?: string;
}

interface FormbodyItem {
  field: string;
  value?: string;
  file?: FormbodyFile;
}

interface Formbody {
  body: FormbodyItem[];
  get(key: string): string | undefined;
  file(key: string): FormbodyFile | undefined;
  has(key: string): boolean;
  select(fields: string[]): { [key: string]: string };
}

Package Sidebar

Install

npm i formbody

Weekly Downloads

294

Version

0.2.2

License

MIT

Unpacked Size

16.7 kB

Total Files

21

Last publish

Collaborators

  • zhiguang