13

I'm developing node server using koa.js

I have looked for some libraries for body parser.

And there are several kinds of koa body parser.

But I don't know what differences btw them including koa-body and koa-bodyparser.

Can you explain it?

Thank you in advance.

DAESEONG KIM
  • 371
  • 3
  • 12

2 Answers2

15

[New answer]

koa-body now support koa version 2. The main difference now remains about file payload parsing. The koa-bodyparser cannot parse files, i.e. multipart/form-data.

[Old answer]

Oh, I got it.

https://github.com/koajs/koa/wiki

koa-body supports koa v1, koa-bodyparser supports koa v2.

And former can parse file, but later can't.

Thanks.

Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
DAESEONG KIM
  • 371
  • 3
  • 12
  • 3
    koa-body does support Koa v2, you just have to get the right branch by doing `npm install koa-body@next`. I've edited the wiki to prevent any confusion for other people. – Saad Dec 18 '16 at 06:45
  • @DAESONG KIM latter* :D – vdegenne Feb 07 '20 at 12:38
  • @saadq are the two branches merged now? I can only see one repository on the wiki. – newguy May 16 '20 at 07:36
3

Both are Koa body parser middleware. I recently faced an issue where I wanted to handle file upload and there comes the main difference.

Koa-body supports -- koa, urlencoded, multipart, json, body, parser, form and

koa-bodyparser supports -- json, urlencoded, koa, body.

So if you are looking for file uploading features , go ahead with koa-body or koa-better-body (which has more wider scopes)

Here is detailed reference

Nicks
  • 16,030
  • 8
  • 58
  • 65