Node.js 如何使用nodejs从安全网络连接到githubapi?

Node.js 如何使用nodejs从安全网络连接到githubapi?,node.js,Node.js,我使用下面的代码从gitHub获取存储库。当我从家庭网络使用它时,我能够检索存储库列表,但是如果我试图从其他网络获取repo,它会给我这个错误:“connect econnreference”。我是nodejs的新手,所以仍然想知道如何着手解决这个问题 有什么想法吗 var https = require("https"); var userName='xyz'; var options = { host :"api.github.com", path : '/users/'+userName+

我使用下面的代码从gitHub获取存储库。当我从家庭网络使用它时,我能够检索存储库列表,但是如果我试图从其他网络获取repo,它会给我这个错误:“connect econnreference”。我是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();
根据需要更改您的选项

var options = {

host:'api.github.com',

path: '/users/' + username+ '/repos',

method: 'GET',

headers: {'user-agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'}

};

我想这样可以

var options = {

host:'api.github.com',

path: '/users/' + username+ '/repos',

method: 'GET',

headers: {'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'}

};

你能提供关于错误的更多细节吗?关于使用的节点版本,操作系统?上面的代码似乎工作正常,所以错误可能是由于环境造成的。当您尝试在代理后运行它时,通常会发生这种情况,从而导致此类错误。是的,我希望在代理后运行它。我如何配置或重写它来运行上面的代码?我知道在这里询问是不合适的,但是您能告诉我您是如何通过该路径的吗。我一整天都在试这个