Javascript 如何使用meteorhacks:npm包调用这个wordcount函数?
我安装是为了在我的Meteor应用程序中使用该软件包 然而,我无法让我的方法工作 客户Javascript 如何使用meteorhacks:npm包调用这个wordcount函数?,javascript,asynchronous,meteor,npm,Javascript,Asynchronous,Meteor,Npm,我安装是为了在我的Meteor应用程序中使用该软件包 然而,我无法让我的方法工作 客户 getWordcount = function getWordcount(words, callback) { Meteor.call('getWordcount', words, callback); } console.log(getWordcount('hello world')); // testing 服务器 Meteor.methods({ 'getWordcoun
getWordcount = function getWordcount(words, callback) {
Meteor.call('getWordcount', words, callback);
}
console.log(getWordcount('hello world')); // testing
服务器
Meteor.methods({
'getWordcount': function getWordcount(words) {
var WordcountApi = Meteor.npmRequire('wordcount');
var wordcount = new WordcountApi({
version: "1.1.1"
});
var words = Async.runSync(function(done) {
wordcount.words, function(err, data) {
done(null, data);
}
});
return words.result;
}
});
我在控制台中返回一条错误消息,上面说:
“调用方法“getWordcount”时出错:内部服务器错误[500]”我的建议
客户
// call meteor method and catch err or results in a callback function
Meteor.call('getWordcount', 'hello world', function(err, results){
if(err) console.error(err);
else console.log(results);
});
服务器
Meteor.methods({
'getWordcount': function getWordcount(words) {
check(words, String);
var wordcount = Meteor.npmRequire('wordcount');
return wordcount(words);
}
});