简体   繁体   中英

How can I call one function from another function in nodejs

I am trying to call a function from another function in Node.js. I am new to this language, so I am trying to implement it in a simple way, but, it is not working as expected. What am I missing?

//Reading from file
var params = require('line-reader’);

var count = 1;
params.eachLine('test.csv', function(line, last) {
     if (count!=1) {
        //Some code
        count++;
     } else {
        //Some code
        count++;
     }

     if (last) {
        // **Call myFunc with count as argument**
        myFunc(count);
     }
});


// Actual code which I am using

function myFunc(count) {
     tradeoff_analytics.dilemmas(count, function(err, res) {
     if (err)
         console.log(err);
     else
         console.log(JSON.stringify(res, null, 2));
     });
}

Yes, the method was undefined, so I was getting an undefined error. Now I have copied the actual code and I am getting this error now:

[Error: Missing required parameters: columns, subject, options]

Your myFunc isn't properly defined, change this:

myFunc(count, function() {
     console.log(count);
});

Into this:

function myFunc(count){
     console.log(count);
}

Or this:

var myFunc = function(count) {
    console.log(count);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM