3

I have a controller with two functions:

module.exports.getQuestionnaire = function(application, req, res) {
}

module.exports.getClientDetails = function(application, req, res) {
}

I want to call the getQuestionnaire function inside the getClientDetails function.

Just calling getQuestionnaire() does not work. How should I do this?

5
  • 2
    Call it like exports.getQuestionnaire() or module.exports.getQuestionnaire() Commented Jan 15, 2018 at 18:37
  • How can I pass an argument, like client id? Commented Jan 15, 2018 at 18:40
  • What do you mean? Pass it just like you do in normal functions exports.getQuestionnaire(clientId) Commented Jan 15, 2018 at 18:45
  • If I do module.exports.getDadosQuestionarioET(clientid, application, req, res ) inside getClientDetails, which have clientid defined, it throws an error: ReferenceError: clientid is not defined. I have also changed the module.exports.getDadosQuestionarioET = function(clientid, application, req, res) { Commented Jan 15, 2018 at 18:49
  • I was doing wrong, it passed. Thanks! Commented Jan 15, 2018 at 18:53

3 Answers 3

5

What I usually do:

const getQuestionnaire = () => {
  //getClientDetails()
}
    
const getClientDetails = () => {
  //getQuestionnaire()
}
    
module.exports = {getQuestionnaire, getClientDetails}
Sign up to request clarification or add additional context in comments.

Comments

1

Define each one as a separate function and then export the functions. Then you can also use the functions on the page

function getQuestionnaire(application, req, res) { }
function getClientDetails (application, req, res) { }
module.exports = {getQuestionnaire, getClientDetails}

Comments

1

you can do like this:

function getQuestionnaire(application, req, res) { 
 //function body
}

function getClientDetails(application, req, res) { 
  getQestionnaire(app,req,res)
}

module.exports= {getQestionnaire,getClientDetails}

1 Comment

module.exports= {getQestionnaire} In this case getClientDetails wont export anymore

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.