node.js – Express validator in the controller

Hi, I use the express validator in nodejs and I have a validation problem. When I was directly validating through the routes, the validation worked, but when I implemented controllers on my system, I didn't know how to validate, because all the ways I tried failed. I am using version 6 of the express validator.

This is my controller

const { check, validationResult } = require('express-validator');
module.exports.formulario_inclusao_noticia = function(app, req, res){
    res.render("admin/form_add_noticia", {validacao: {}, noticia : {}});
}

module.exports.noticia_salvar = function(app, req, res){
    check('titulo').isLength({ min: 5 }).withMessage('O título deve ter no mínimo 5 letras')
    var noticia = req.body;
    const errors = validationResult(req);
    console.log(errors);
    if (!errors.isEmpty()) {
        return res.render('admin/form_add_noticia', { validacao: errors.array(), noticia : noticia});
        return;
    }
    var connection = app.config.dbConnection();
    var noticiasModel = new app.app.models.noticiasModel(connection);

    noticiasModel.salvarNoticia(noticia, function(error, result){
        res.redirect("/noticias");
    });
}

The route:

module.exports = function(app){
    app.get('/formulario_inclusao_noticia', function(req, res){
        app.app.controllers.admin.formulario_inclusao_noticia(app, req, res);
    });
    app.post('/noticias/salvar', function(req, res){
            app.app.controllers.admin.noticia_salvar(app, req, res);
    });
}

The view:




    
    Formuláio de cadastro de Notícia



    

Adicionar notícia


<% if(validacao) { %>
    <% for(var i = 0; i < validacao.length; i++) { %>
  • <%= validacao(i).msg %>
  • <% } %>
<% } %>





How can I make this validation work correctly?