Consider the following code, take from this example: How is an HTTP POST request made in node.js?
var request = require('request');
request.post(
'http://www.yoursite.com/formpage',
{ json: { key: 'value' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
How do I make the variable body known globally in the program and not only in the anonymous function?
The problem I face is that my function is surrounded by a function which has to return the value of what is queried in the request of the url.