Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 784
EFO Avatar asked Apr 23 '26 04:04

EFO


2 Answers

What I usually do:

const getQuestionnaire = () => {
  //getClientDetails()
}
    
const getClientDetails = () => {
  //getQuestionnaire()
}
    
module.exports = {getQuestionnaire, getClientDetails}
like image 82
yBrodsky Avatar answered Apr 25 '26 17:04

yBrodsky


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}
like image 35
M B Avatar answered Apr 25 '26 17:04

M B