Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

node js validate body without middleware

function validateRegForm(req, res, next){
  console.log('Validating form...');
  if(!req.body.password){
    return res.send(500, 'Need a password');
  };
  next();
};

app.post('/regForm'
, validateRegForm
, function(req,res){
  // If Express calls this fn, the previous fn did next(), not res.send()
  console.log('Doing something with this valid form');
  res.redirect('/regForm/complete');
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #node #js #validate #body #middleware
ADD COMMENT
Topic
Name
5+5 =