admin管理员组文章数量:1426472
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
1 Answer
Reset to default 4Your 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);
};
本文标签: javascriptHow can I call one function from another function in nodejsStack Overflow
版权声明:本文标题:javascript - How can I call one function from another function in nodejs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745401496a2657060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论