EFO
EFO

Reputation: 183

Using a module.export function inside the same file same file where it's implemented

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?

Upvotes: 3

Views: 1909

Answers (3)

yBrodsky
yBrodsky

Reputation: 5041

What I usually do:

const getQuestionnaire = () => {
  //getClientDetails()
}
    
const getClientDetails = () => {
  //getQuestionnaire()
}
    
module.exports = {getQuestionnaire, getClientDetails}

Upvotes: 5

F.Moez
F.Moez

Reputation: 19

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}

Upvotes: 1

M B
M B

Reputation: 2326

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}

Upvotes: 1

Related Questions