node.js - 错误:在 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
}
解决方案
推荐阅读
- javascript - 如何使 date-fns 的格式函数以 UTC(不是本地时间)返回时间?
- android - 对 com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay 的依赖不满意
- arrays - 在Excel VBA中制作一个由来自不同工作表的多个范围值组成的数组
- python - 如何在运行可执行的 python 脚本(如 .command 文件)时使用外部 python 模块,如模块“请求”?
- sql-server - 将 UTC 转换为所需的时区
- html - Edge 和 Chrome 不尊重 ::after 绝对位置
- python - 语句中任何、所有和多个“in”的组合是什么意思?
- sql - 如何在第一次出现时停止 WHERE?
- snowflake-cloud-data-platform - Snowflake 上的区域,如果我们有两个区域,设置 VPN 的最佳做法是什么
- reporting-services - 根据值计数将自定义渐变应用于图表