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

126
Views
(NodeJS) How to Validation in 'Routes' and send to 'Controller' [MVC]?

i have a problem in my code: idols.js

router.post(
'/creating',

check('name', 'Min 1 and Max 50!').isLength({ min: 1, max: 50 }),

(req, res) => {
  
  const errors = validationResult(req);
  if (!errors.isEmpty()) {      
    alertError = errors.array();
    res.render('idols/create', {alertError});      
  }
  else {  
    //Next if value is good
  }      
});

and idolsController.js

const idols = require('../models/idols'); 
class idolsController {

creating(req, res, next) {
    const idols_data = new idols(req.body);
    idols_data.save()
            .then(() => res.redirect('/idols/edit'))
            .catch(next());
}
module.exports = new idolsController;

my idols.js when not using logic validation

router.post('/creating', idolsController.creating); 

--- My question: I want to convert the code in the 3rd paragraph to the code in the 1st paragraph (in this topic) thank for reading.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your question is unclear. Please review and update

about 4 years ago · Juan Pablo Isaza 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!