首页 > 解决方案 > 错误:在 TCPConnectWrap.afterConnect 处连接 ETIMEDOUT 127.0.0.1:3000 [as oncomplete]

问题描述

我是nodejs的新手。我从包含以下代码的浏览器运行 API 调用,10-20 秒后我收到错误(在代码下方)。

const request = require("request");
app.get("/update-user", (req, res) => {

  if (req.query.id) {
    var separateReqPool = { maxSockets: 20 };
    const url = `https://localhost:3000/api/users?id=${req.query.id}`;
    request({url, separateReqPool}, (error, response, body) => {
      if (error) console.log(error);

      console.log(body);
    });
  }
});

app.get("/api/users", (req, res) => {
  if (req.query.id) {
    const id = req.query.id;

    Order.findById(id)
      .then((data) => {
          console.log(data);
          res.send(data);
      })
      .catch((err) => {
        res.status(500).send({ message: "Error retrieving user with id " + id });
      });
  } else {
    Order.find()
      .then((user) => {
        res.send(user);
      })
      .catch((err) => {
        res.status(500).send({
          message:
            err.message || "Error Occurred while retriving user information",
        });
      });
  }
});

10-20 秒后,我收到错误消息,浏览器上没有显示任何内容。

Error: connect ETIMEDOUT 127.0.0.1:3000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -60,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000
}

标签: node.jsrequest

解决方案


推荐阅读