Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
this.validateBody is not validating the keys even keys are in body of request nodejs koa
yield this.validateBody({ password: 'required', email_id: 'required' });

trying to validate the request body but when everything is in it, it still says Fields are required. everything is in it.

node 12.20.0

koa-validation 0.1.9

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

// Use koa-validate

'use strict';
var koa = require('koa');
var app = koa();
var router = require('koa-router')();
require('koa-validate')(app);
 
app.use(require('koa-body')({multipart:true , formidable:{keepExtensions:true}}));
app.use(router.routes()).use(router.allowedMethods());
router.post('/signup', function * () {
    //optional() means this param may not in the params.
    this.checkBody('name').optional().len(2, 20,"are you kidding me?");
    this.checkBody('email').isEmail("your enter a bad email.");
    this.checkBody('password').notEmpty().len(3, 20).md5();
    //empty() mean this param can be a empty string.
    this.checkBody('nick').optional().empty().len(3, 20);
    //also we can get the sanitized value 
    var age = this.checkBody('age').toInt().value;
    yield this.checkFile('icon').notEmpty().size(0,300*1024,'file too large').move("/static/icon/" , function*(file,context){
        //resize image
    });
    if (this.errors) {
        this.body = this.errors;
        return;
    }
});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!