2
As it is possible to return the value of a remote json and read as string, example when I get the json it prints the whole result as in the image below. code below:
var https = require('https');
var optionsget = {
host : 'the-evie.com',
port : 443,
path : '/playerscript/pc/Droust',
method : 'GET'
};
console.info('Options prepared:');
console.info(optionsget);
console.info('Do the GET call');
var reqGet = https.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
console.info('GET result:\n');
process.stdout.write(d);
console.info('\n\nCall completed');
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
what I wanted was to make this filtered as for example the username, was able to receive the value by key, ie key username value Droust.
how it is possible to use it outside the function, in another function?
– Wladi Veras
I didn’t quite understand your question. Use what outside the function?
– Samuel Rizzon
the variable it exists inside the var reqGet = https.request(optionsget, Function(res) { }); however I cannot use it outside
– Wladi Veras
I think I get it now. You can declare var obj outside the context of its functions. And within your function you make the obj variable receive your text and be converted to object. And then you can use it wherever you want in your code.
– Samuel Rizzon
@
Samuelhenriquerizzon (cc @Carloseduardo) sehttps.request
is asynchronous that’s not true!– Sergio