在服务器端流星方法中没有定义require?

时间:2015-06-13 02:55:01

标签: node.js meteor

我有一个Meteor方法,我只在server文件夹中定义。

服务器/ methods.js

Meteor.methods({

    locationInfoByZipcode: function(zipcode){

        check(zipcode, String);
        var https = require('https');

    },
});

我在客户端上打电话:

Meteor.call("locationInfoByZipcode", "94043", function(error, response){ 
  console.log(error); 
  console.log(response);
});

这是服务器控制台中的错误:

I20150612-19:48:28.092(-7)? Exception while invoking method 'locationInfoByZipcode' ReferenceError: require is not defined
I20150612-19:48:28.092(-7)?     at [object Object].Meteor.methods.locationInfoByZipcode (app/server/meteor_methods.js:109:15)
I20150612-19:48:28.092(-7)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1)
I20150612-19:48:28.092(-7)?     at packages/ddp/livedata_server.js:648:1
I20150612-19:48:28.092(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150612-19:48:28.093(-7)?     at packages/ddp/livedata_server.js:647:1
I20150612-19:48:28.094(-7)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150612-19:48:28.094(-7)?     at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150612-19:48:28.094(-7)?     at packages/ddp/livedata_server.js:546:1
呃......不知道为什么会这样。如果我打开Meteor Shell,我可以正常控制日志require

1 个答案:

答案 0 :(得分:1)

如果您从节点核心引用HTTPS,则可以从meteor中获取它:

var https = Npm.require('https');

无需安装任何其他软件包。节点核心中的任何模块都可以在服务器上以这种方式使用。