Nodejs 上的端口 3000 权限被拒绝

发布于 2025-01-13 18:27:41 字数 1361 浏览 3 评论 0原文

当我在端口 3000 上运行我的 nodejs 项目时,出现以下错误:

Error: listen EACCES: permission denied :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1330:16)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1465:7)
    at Function.listen (F:\Projects\NodeJS\Nodejs start\Nodejs start\node_modules\express\lib\application.js:618:24)  
    at Object.<anonymous> (F:\Projects\NodeJS\Nodejs start\Nodejs start\app.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EACCES',
  errno: -4092,
  syscall: 'listen',
  address: '::',
  port: 3000

不仅在端口 3000 上,而且在任何端口上,程序都无法运行,并且出现上述错误。 为了解决这个问题,我在CMD上运行net stop winnat,我得到:

Windows NAT 驱动程序服务未启动。

为了启动 winnat,我运行 net start winnat ,我明白了

Windows NAT 驱动程序服务已成功启动。

但问题并没有解决,除了重启系统还有其他办法吗?

when i run my nodejs project on port 3000, get following error:

Error: listen EACCES: permission denied :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1330:16)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1465:7)
    at Function.listen (F:\Projects\NodeJS\Nodejs start\Nodejs start\node_modules\express\lib\application.js:618:24)  
    at Object.<anonymous> (F:\Projects\NodeJS\Nodejs start\Nodejs start\app.js:34:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EACCES',
  errno: -4092,
  syscall: 'listen',
  address: '::',
  port: 3000

Not only on port 3000, but also on any port, the program does not run, and the mentioned error occur.
for solving this problem, i run net stop winnat on CMD, i get:

The Windows NAT Driver service is not started.

for start the winnat, i run net start winnat , i get

The Windows NAT Driver service was start successfully.

But the problem was not solved.Is there any other way but to restart the system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妥活 2025-01-20 18:27:41
  • 您可以尝试在Windows系统上,重新启动“主机网络”服务
    服务”可能会解决该问题。

  • 或尝试多次重新启动计算机

  • 或尝试在管理员权限下打开CMD并运行:

    网络停止winnat

    网络启动winnat

  • You can try On Windows systems, restarting the service "Host Network
    Service" may resolve the issue.

  • or try to restart your computer more than one time

  • or try open CMD under admin rights and run :

    net stop winnat

    net start winnat

忆悲凉 2025-01-20 18:27:41

读取环境变量时,应将其转换为数字。
尝试将 parseInt() 添加到变量中:

const port = parseInt(process.env.PORT) || 3000;

When reading an environment variable, you should convert it to a number.
Try adding parseInt() to the variable:

const port = parseInt(process.env.PORT) || 3000;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文