Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED) C:\Wi...

2026年10月10日 20:18 11.04 秒 success

错误信息

API Error: Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED) C:\Windows\System32>netsh advfirewall firewall add rule name="AllowPort64755" dir=in action=allow protocol=TCP localport=64755 确定。 PS C:\WINDOWS\system32> Test-NetConnection -ComputerName 127.0.0.1 -Port 64755 警告: TCP connect to (127.0.0.1 : 64755) failed ComputerName : 127.0.0.1 RemoteAddress : 127.0.0.1 RemotePort : 64755 InterfaceAlias : Loopback Pseudo-Interface 1 SourceAddress : 127.0.0.1 PingSucceeded : True PingReplyDetails (RTT) : 0 ms TcpTestSucceeded : False PS C:\WINDOWS\system32> netstat -ano | findstr 64755 PS C:\WINDOWS\system32> const server = app.listen(64755, '0.0.0.0', () => { >> console.log('Server running on port 64755'); >> }); 所在位置 行:1 字符: 46 + const server = app.listen(64755, '0.0.0.0', () => { + ~ “(”后面应为表达式。 所在位置 行:1 字符: 27 + const server = app.listen(64755, '0.0.0.0', () => { + ~~~~~ 赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。 所在位置 行:1 字符: 34 + const server = app.listen(64755, '0.0.0.0', () => { + ~~~~~~~~~ 赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。 所在位置 行:1 字符: 46 + const server = app.listen(64755, '0.0.0.0', () => { + ~ 赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression PS C:\WINDOWS\system32>

AI 解决方案

🌐 错误翻译

原文:API Error: Connection refused — a firewall or proxy may be blocking it (ECONNREFUSED); 所在位置 行:1 字符: 46 + const server = app.listen(64755, '0.0.0.0', () => { ... 赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。
译文:API错误:连接被拒绝 —— 可能是防火墙或代理阻止了连接(ECONNREFUSED);第1行第46字符处 + const server = app.listen(64755, '0.0.0.0', () => { ... 赋值表达式无效。赋值运算符输入必须是一个可赋值对象,例如变量或属性。

🎯 原因分析

  • 直接原因:你在 PowerShell 中直接输入了 Node.js 风格的 JavaScript 代码(const server = app.listen(...)),PowerShell 无法解析该语法,因此抛出 ParserError。

  • 关联问题:由于服务从未启动成功,端口 64755 上没有任何进程监听,netstat 查询无结果,Test-NetConnection 连接失败,最终导致 API 请求得到 ECONNREFUSED。

💡 解决方案

将代码保存为 .js 文件并通过 Node.js 执行,例如保存为 server.js:

const express = require('express');
const app = express();

const server = app.listen(64755, '0.0.0.0', () => {
  console.log('Server running on port 64755');
});

// 优雅关闭
process.on('SIGTERM', () => server.close(() => console.log('Server stopped'));

然后运行:

node server.js

🛡️ 预防措施

  • 分离脚本与命令行:永远不要在 PowerShell/CMD 中直接输入多行编程语言代码,应使用独立的 .js 文件并通过对应运行时执行。

  • 验证启动状态:启动服务后,使用 netstat -ano | findstr <PORT> 或 Test-NetConnection 127.0.0.1 -Port <PORT> 确认进程已正常监听,再发起客户端请求。