1

I've got a Meteor Method that I've only defined in the server folder.

server/methods.js

Meteor.methods({

    locationInfoByZipcode: function(zipcode){

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

    },
});

I call it on the client:

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

This is the error in the server console:

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

Uhhh... not sure why this is happening. If I open a Meteor Shell I can console log require just fine.

2
  • 1
    what are you trying to do? why not use the HTTPS object? If you must include npm packages, then please look for the million and one questions on how to require npm packages in meteor (i.e., use the npm package). Jun 13, 2015 at 4:23
  • I think require's code is a lot cleaner to read and write than using the HTTPS object directly. But yeah, I just Googled and it turns out I need to use the npm atmosphere package. Bah. Jun 13, 2015 at 5:11

1 Answer 1

1

If you are referring to HTTPS from node core, you can require it from meteor with:

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

without having to install any additional packages. Any module in node core can be required this way on the server.

1
  • I'm pretty angry at Meteor for doing this. Sometimes you need to require a local file, not an NPM package.
    – Andy
    Jul 17, 2015 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.