1

Im using Node and Express for a API REST. Is it possible to add a condition IF statemtent in the router? Just like this:

.route('/app')
    .post(
          openPool
        , checkToken
        , checkCondition //set req.condition = true
        (req, res, next) => {
              if (req.condition === true){
                Controller1
              , Controller2
              }
              next()
        }
        , sendResponse
);

It doesnt throw any error, it just doesnt execute the code of Controller1 and Controller2

0

1 Answer 1

1

If controllers are functions you should do something like this:

Controller1(req, res, () => Controller2(req, res, next))`
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.