I assume you're trying to make a synchronous call from a node.js script,
then when it finishes, do other things as well.
If your other scripts are also node.js, you would probably add a `callback`
parameter to your _call method, and call it when done.
Example:
function _call(cb) {
request.get(someUrl, function(err, response) {
// handle err if any
if(err) {return cb(err);}
// do stuff with body, i.e. your JSON.parse
// then call the callback
cb(null, response.body);
});
});
// then export the function
module.exports.call = _call;
You would call this as follows, from other modules:
var myModule = require('./linode-module.js');
// when you call the module, pass it a function that will be executed
when done. That is where you get the results.
myModule.call(function(err, body) {
// this function will receive your response.
console.log(body);
// now you can do other useful things with it.
});
Hope that helps.
Zlatko
On Wednesday, January 7, 2015 1:05:42 AM UTC+1, Tiago Hillebrandt wrote:
>
> Hey guys,
>
> I need to do an HTTPS request to the Linode API.
>
> That said, I am looking if would be possible to return an HTTPS response
> as value on this function: http://paste.ubuntu.com/9684987/
>
> I tried some specific things to make the thread wait until request ends,
> like *setTimeout()* and *while (!req.finished) {}*, but nothing seems to
> work as expected.
>
> This is my first Node.js implementation, so I am not sure if this would be
> the better way to perform this action.
>
> Do you guys have any suggestions on this?
>
> Thanks in advance!
>
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/ca4f3548-b1bf-4d45-a388-b5cdb722c8d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.