I have a function in my app.js that I would like to use in my routes.js file, but the export is not working properly.
app.js:
module.exports = function extractquestions(){
extractq();
};
routes.js:
let extractquestions = require('../app.js');
the error I get :
TypeError: extractquestions is not a function
CodePudding user response:
function extractquestions() = { /* your function */}
exports.extractquestions = extractquestions
CodePudding user response:
The other guy is right. But you also do like this:
app.js:
function print(x){
console.log(x);
}
module.exports = function printSenctence(sentence) {
print(sentence);
}
and route.js:
const printSenctence = require('./app');
printSenctence("Everything is awesome!!");
Hope I help ;)