以下のコードを使用して、gitHubからリポジトリを取得しています。ホームネットワークから使用すると、リポジトリのリストを取得できますが、他のネットワークからリポジトリを取得しようとすると、「connectECONNREFUSED」というエラーが発生します。私はnodejsを初めて使用するので、この問題を解決する方法をまだ考えています。
何か案は?
var https = require("https");
var userName='xyz';
var options = {
host :"api.github.com",
path : '/users/'+userName+'/repos',
method : 'GET'
}
var request = https.request(options, function(response){
var body = '';
response.on('data',function(chunk){
body+=chunk;
});
response.on('end',function(){
var json = JSON.parse(body);
var repos =[];
json.forEach(function(repo){
repos.push({
name : repo.name,
description : repo.description
});
});
console.log('the repos are '+ JSON.stringify(repos));
});
});
request.on('error', function(e) {
console.error('and the error is '+e);
});
request.end();