Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

415
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda