Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用meteorhacks:npm包调用这个wordcount函数?_Javascript_Asynchronous_Meteor_Npm - Fatal编程技术网

Javascript 如何使用meteorhacks:npm包调用这个wordcount函数?

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

我安装是为了在我的Meteor应用程序中使用该软件包

然而,我无法让我的方法工作

客户

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