Answer the question
In order to leave comments, you need to log in
How to get variable from request in Node.js?
Good afternoon, I'm doing data parsing using https://www.npmjs.com/package/request via api from YouTube I'm getting
a response, I'm processing it through for, but I just can't get all this stuff out of the scope of request.get(...)
Maybe there is an option?
Answer the question
In order to leave comments, you need to log in
Sorry, isn't the answer below in the documentation?
request
.get('http://google.com/img.png')
.on('response', function(response) {
console.log(response.statusCode) // 200
console.log(response.headers['content-type']) // 'image/png'
})
выведите в консоль Response. Там должен быть объект body или data
It is necessary to display the variable outside of request
request.get("https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q="+result[k]['song']+'+'+result[k]['song']+"&type=video&key=AIzaSyAvDAdEnqrStOJNnpnGy9BkrC_sG-gcHIU", function(err,res,body){
if(res.statusCode == 200 ) {
var c = JSON.parse(body);
console.log(c['items'][0]['id']['videoId']);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question