I've searched through dozens of sites but haven't really found a solution for my problem.
First of all I want to wait for 'response' callback to finish execution but I'm not sure how I'm able to achieve this. Promise and async/await didn't really help me or at least I'm not sure how to use it in this particular situation.
Secondly how can I make response available outside of this callback event.
response_ = response
didn't work.
let response_ = null
request = net.request(specific_info['host'])
request.on('response', (response) => {
// here I want something like response_ = response
console.log(`STATUS: ${response.statusCode}`)
console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
response.on('data', (chunk) => {
console.log(`BODY: ${chunk}`)
})
response.on('end', () => {
console.log('No more data in response.')
})
})
request.end()
// here I want to wait until 'response' finished execution
console.log(`STATUS: ${response_.statusCode})
The framework I'm using is Electron