1

I have 2 files QueryExecution.js and app.js; from app.js am calling a function query_result which is in QueryExecution.js. But when I made the call in app.js am getting object.function is not a function.

Kindly apologize for any stupid mistakes :( Thanks in advance for your time and help

I tried to print the object(realtime_chart_new) that I created to call the function. the object is printing the entire function content.

QueryExecution.js

function query_result(connection,sql) {
    .......query statements and processing content .....
        return CountOrders, TotalAmt;
}
module.exports = query_result;

app.js

var connection = {
    .....connection statements .....
};

var realtime_chart_new = require('./QueryExecution.js');
var SalesCountOrders, SalesTotalAmt = realtime_chart_new.query_result(connection,sql);```



#Below is the error statements:

var SalesCountOrders, SalesTotalAmt = realtime_chart_new.query_result(connection,sql);
TypeError: realtime_chart_new.query_result is not a function
5
  • Does realtime_chart_new contain query_result, or is it printing the entire function directly? Also, what is exported from the file 'QueryExecution.js' ? Commented Jun 4, 2019 at 12:08
  • realtime_chart_new directly prints the entire code that I wrote inside query_result Commented Jun 4, 2019 at 12:10
  • That would probably mean realtime_chart_new is default export and you would need to call it directly like realtime_chart_new() Commented Jun 4, 2019 at 12:11
  • That's great !!!! it worked !!! But I didn't understand how it worked with just object name and without function name. Pls, post this as the answer. I'll mark it as accepted. Thank you so much :) Commented Jun 4, 2019 at 12:17
  • To add answer, edit your question to reflect the way you've exported in your QueryExecution.js Commented Jun 4, 2019 at 12:20

1 Answer 1

1

You have overridden module exports with query_result, so now require('./QueryExecution.js') returns a function.

This will give you expected result:

module.exports.query_result = query_result;

OR

module.exports = {
    query_result: query_result
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.