Will your return resultstr; launched before the on('complete' callback is called because it is asynchronous, so your htmlstring will be empty as a result? I think you need to have the callback as a parameter for your loadHtmlUrl , for example:
var rest = require('restler'); var loadHtmlUrl = function(weburl, callback) { var resultstr = rest.get(weburl).on('complete', function(result) { callback(result.request.res.rawEncode); }); };
And then call it like this:
var htmlstring = null; loadHtmlUrl('http://google.com', function(rawEncode) { htmlstring = rawEncode;
I think this will solve the future problems that you will have. However, I think the real problem that you are facing is that result.request does not have a res property. I think my change above can solve this problem (not quite sure how). If not, then I would recommend looking at what properties result.request has as a debug starter ...
source share