node.js - How do I retrieve developer's repository information from github using nodejs? -
this follows series of tutorials doing learn nodejs. want access repository information of users on developer.github.com. when try use following piece of code shows error:
json.foreach(function(repo){ ^ typeerror: object # has no method 'foreach'
var https=require("https"); var username= "ollieparsley"; var options={ host: "api.github.com", path: "/users/" +username+ "/repos", method: "get", /*customheaders: { "user-agent": "app" }*/ }; var request= https.request(options, function(response){ var body=''; response.on("data", function(chunk){ body+=chunk.tostring("utf8"); }); response.on("end", function(){ var repos=[]; var json=json.parse(body); json.foreach(function(repo){ repos.push({ name:repo.name, description:repo.descripton }); }); console.log("repos: ", repos); }); }); request.end();
any pointers why error object has no method 'foreach'?
use object.keys(json).foreach(...)
instead. var repo = json[key];
inside foreach
block.
Comments
Post a Comment