Skip to content

Instantly share code, notes, and snippets.

@bmax
Last active March 14, 2017 17:28
Show Gist options
  • Save bmax/e2b4b59dfdf48ad83761843b0d3a26f8 to your computer and use it in GitHub Desktop.
Save bmax/e2b4b59dfdf48ad83761843b0d3a26f8 to your computer and use it in GitHub Desktop.
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