0
var signupHelper = require('./util/signuphelper');

router.post('/signup', signupHelper.checkEmpty, signupHelper.test, function(req,res){   });

I'm new to node.js (don't know if it is called callback.). My problem is, when signupHelper.checkEmpty has no errors it doesn't return anything, so it cannot proceed to .test. How can i fix this? Cos if there's no error, I want to check the data if it doesn't exist in the db so I need to call signupHelper.test to check.

In my checkEmpty

exports.checkEmpty = function(req,res){ 
------- some code here -------  
if(errors.length > 0){
        req.flash('errors', errors);
        res.redirect('/signup');
    }
}

exports.test = function(req,res) { some code....}
2
  • If their is no error..Have you checked the result by consoling it in node server? Commented Aug 17, 2015 at 10:40
  • Yes. I also tried to use return after the if statement just to test so I can proceed to signupHelper.test. But it's not working. The browser keeps loading. But when it encounters error (the if statement is true) then the browser redirects (as expected). Commented Aug 17, 2015 at 10:43

1 Answer 1

4

You need to call the next parameter in the router callback function, look at the next(); that comes from the router callback.

exports.checkEmpty = function(req,res,next){ 
------- some code here -------  
if(errors.length > 0){
        req.flash('errors', errors);
        res.redirect('/signup');
    }else{
        next(); // This will pass the route to the next callback in chain.
    }
}

exports.test = function(req,res,next) { some code....}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.