javascript - How can I call one function from another function in nodejs - Stack Overflow

I am trying to call a function from another function in Node.js. I am new to this language, so I am try

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]

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]
Share Improve this question edited Mar 10, 2016 at 19:17 Norrin Radd 31 bronze badge asked Mar 9, 2016 at 16:07 Swapnil Shailesh SrivastawaSwapnil Shailesh Srivastawa 2711 gold badge3 silver badges7 bronze badges 7
  • 1 Where is myFunc defined? – Maria Ines Parnisari Commented Mar 9, 2016 at 16:09
  • @miparnisari I doubt its existance. – Nonemoticoner Commented Mar 9, 2016 at 16:10
  • It's worth noting that this isn't really a node question, but a javascript question, as node is a server side javascript environment and this turns out to be a question about how to define a function. – linuxdan Commented Mar 9, 2016 at 16:29
  • 1 Now that problem has nothing to do with the code you are showing us – Fabio Antunes Commented Mar 9, 2016 at 16:32
  • Yes. That was my mistake and solved by @miparnisari – Swapnil Shailesh Srivastawa Commented Mar 9, 2016 at 16:34
 |  Show 2 more ments

1 Answer 1

Reset to default 4

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);
};

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401496a4626124.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信