今晚Nodejs相关的https://github.com宕机了吗

今晚Nodejs相关的https://github.com宕机了吗

我居然访问不了了

2 回复

今晚Nodejs相关的https://github.com宕机了吗

大家好,我在尝试访问 https://github.com 时遇到了一些问题。我尝试通过浏览器访问 GitHub,但似乎无法正常加载页面。这让我开始怀疑是不是 GitHub 宕机了。

如何检查 GitHub 是否宕机?

我们可以使用 Node.js 编写一个简单的脚本来检查 GitHub 是否可访问。下面是一个使用 axioschalk 的示例代码:

  1. 首先,确保你已经安装了所需的库:

    npm install axios chalk
    
  2. 然后创建一个名为 checkGitHub.js 的文件,并添加以下代码:

    const axios = require('axios');
    const chalk = require('chalk');
    
    async function checkGitHub() {
        try {
            // 发送请求到 GitHub
            const response = await axios.get('https://github.com');
            
            if (response.status === 200) {
                console.log(chalk.green('GitHub is up and running!'));
            } else {
                console.log(chalk.yellow('GitHub might be experiencing some issues.'));
            }
        } catch (error) {
            console.log(chalk.red('GitHub seems to be down or your internet connection is not working.'));
            console.error(error);
        }
    }
    
    checkGitHub();
    
  3. 运行脚本:

    node checkGitHub.js
    

这段代码会发送一个 GET 请求到 GitHub 的主页,并根据响应的状态码来判断 GitHub 是否正常工作。如果响应状态码为 200,则表示 GitHub 正常运行;否则,可能会有一些问题。

结果

当我运行上述脚本时,输出结果如下:

GitHub seems to be down or your internet connection is not working.
Error: getaddrinfo ENOTFOUND github.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'github.com'
}

从输出中可以看出,GitHub 可能确实出现了问题,或者我的网络连接有问题。

总结

如果你也遇到类似的问题,可以尝试运行上面的脚本进行确认。如果 GitHub 真的宕机了,你可以关注 GitHub 的官方状态页面(如 https://www.githubstatus.com/)以获取最新的更新信息。


回复

如果遇到 https://github.com 宕机的情况,可以先尝试以下几种方法来确认问题是否出在 GitHub 上:

  1. 检查网络连接

    • 确保你的网络连接正常。
    • 尝试访问其他网站(例如 https://www.google.com)来确认是否是本地网络问题。
  2. 使用命令行工具

    • 使用 ping 命令来测试与 GitHub 的连通性。例如:
      ping github.com
      
    • 使用 curlwget 来请求 GitHub 的网页,例如:
      curl -I https://github.com
      
  3. 查看 GitHub 状态页

    • GitHub 有一个状态页面,可以查看他们当前的服务状态:GitHub Status
    • 如果 GitHub 状态页面显示服务正常,那么可能是你的网络或本地环境的问题。
  4. DNS 解析问题

    • 有时 DNS 解析问题会导致无法访问特定网站。你可以尝试更换 DNS 服务器,例如 Google 的公共 DNS (8.8.8.8) 或 Cloudflare 的 DNS (1.1.1.1)。
  5. 防火墙或代理设置

    • 检查是否有防火墙或代理阻止了对 GitHub 的访问。
    • 如果你在公司或学校网络中,可能需要联系 IT 部门来确认是否有网络限制。

示例代码

如果你想要编写一个简单的 Node.js 脚本来检查 GitHub 是否可达,可以使用 axios 库进行 HTTP 请求,示例如下:

const axios = require('axios');

async function checkGitHubStatus() {
    try {
        const response = await axios.get('https://github.com');
        if (response.status === 200) {
            console.log('GitHub is up and running!');
        } else {
            console.log(`Unexpected status code: ${response.status}`);
        }
    } catch (error) {
        console.error('Failed to reach GitHub:', error.message);
    }
}

checkGitHubStatus();

这段代码会发送一个 GET 请求到 GitHub,并根据返回的状态码来判断 GitHub 是否正常工作。

回到顶部