Last active
March 14, 2017 17:28
-
-
Save bmax/e2b4b59dfdf48ad83761843b0d3a26f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getNodes() { | |
return new Promise((resolve, reject) => { | |
http.get('http://localhost:3000', (res) => { | |
const statusCode = res.statusCode; | |
const contentType = res.headers['content-type']; | |
res.setEncoding('utf8'); | |
let rawData = ''; | |
res.on('data', (chunk) => rawData += chunk); | |
res.on('end', () => { | |
try { | |
let parsedData = JSON.parse(rawData); | |
parsedData.forEach( function (data, idx) { | |
nodes[0][idx].label = data.label; | |
}); | |
resolve(nodes); | |
} catch (e) { | |
console.log(e.message); | |
} | |
}); | |
}).on('error', (e) => { | |
console.log(`Got error: ${e.message}`); | |
}); | |
}); | |
}; | |
async function main() { | |
var nodes = await getNodes(); | |
// use nodes here | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment