nodejs: Koa , form in pug gives undefined

381
April 30, 2017, at 03:31 AM

I have a form in pug with just one input

form(action="/" method="POST")
 label Enter URL to shorten
 br
 input(name="url" type="url") 
 button(type="submit") Submit

I use koa-pug to get the input

async function handleForm (ctx) {
   console.log(ctx.request.body);
}

However this logs undefined

I also use koa-body as body parser

app.use(body());
Answer 1

In your form, you are calling your koa backend with a POST method. So to get the body, you need to use something like co-body,

...
const parse = require('co-body');
...
async function handleForm (ctx) {
  let body = await parse(ctx);
  console.log(body);
}
READ ALSO
How to test javascript in node repl (no browser)?

How to test javascript in node repl (no browser)?

I have 2 files mycodejs and mycode

332
Google Drive API: convert doc to pdf and save it back to Google Drive

Google Drive API: convert doc to pdf and save it back to Google Drive

Is it possible to convert a google doc file to pdf and save that pdf back to the google drive without exporting and uploading? I prefer to use NodeJS API, but REST API is suitable as well

451
How to use imagick with php in aws lambda?

How to use imagick with php in aws lambda?

Currently Amazon lambda does supports only nodejs and python

414
Get wrong parameter from get method in nodejs

Get wrong parameter from get method in nodejs

I'm trying to send get method request and want to pass value in URL

326