how to use nodejs async module?
<p>This is a different question and I am unable to get a solution for this, please do not mark it duplicate.</p>

<p>I cannot access variable op outside the function. Should I be using a async module of nodjes?
I have two console.logs. But only inside function log works.</p>

<p>I have tried other questions answers. Still it is not working</p>

<pre><code>var http = require('http');
console.log("hi")
var options = {
    host: 'api.usergrid.com',
    path: '/siddharth1/sandbox/restaurants'
};
var op = []; //declaring outside function
var req = http.get(options, function(res) {

    // Buffer the body entirely for processing as a whole.
    var bodyChunks = [];
    res.on('data', function(chunk) {
        // You can process streamed parts here...
        bodyChunks.push(chunk);
    }).on('end', function() {
        var body = Buffer.concat(bodyChunks);

        // ...and/or process the entire body here.
        var body2 = JSON.parse(body);

        op = body2.entities.map(function(item) {
            return item.name;
        });
        console.log(op); // only this works
    })
});

req.on('error', function(e) {
    console.log('ERROR: ' + e.message);
});


console.log("outside function " + op); //this doesnt work


console.log('Server listening on port 80');
</code></pre>