【报错】[Nest] Error: listen EACCES: permission denied 0.0.0.0[NestFactory] Starting Nest application...

当我运行我的nest.js服务的时候,出现了以下👇这种报错:

[Nest] 44132  - 2024/12/11 09:36:19     LOG [NestFactory] Starting Nest application...
[Nest] 44132  - 2024/12/11 09:36:19     LOG [InstanceLoader] AppModule dependencies initialized +10ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [InstanceLoader] AbcModule dependencies initialized +0ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RoutesResolver] AbcController {/}: +3ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RouterExplorer] Mapped {/, GET} route +2ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RouterExplorer] Mapped {/abc, POST} route +0ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RouterExplorer] Mapped {/abc, GET} route +0ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RouterExplorer] Mapped {/getById, GET} route +1ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [RouterExplorer] Mapped {/add, POST} route +0ms
[Nest] 44132  - 2024/12/11 09:36:19     LOG [NestApplication] Nest application successfully started +2ms
[Nest] 44132  - 2024/12/11 09:36:19   ERROR [NestApplication] Error: listen EACCES: permission denied 0.0.0.0:3000 +2ms
node:net:1881
      const error = new UVExceptionWithHostPort(rval, 'listen', address, port);
                    ^

Error: listen EACCES: permission denied 0.0.0.0:3000
    at Server.setupListenHandle [as _listen2] (node:net:1881:21)
    at listenInCluster (node:net:1946:12)
    at Server.listen (node:net:2044:7)
    at ExpressAdapter.listen (E:\IntellectronSec\Study Project\241210-nest-stu\node_modules\@nestjs\platform-express\adapters\express-adapter.js:95:32)
    at E:\IntellectronSec\Study Project\241210-nest-stu\node_modules\@nestjs\core\nest-application.js:183:30
    at new Promise (<anonymous>)
    at NestApplication.listen (E:\IntellectronSec\Study Project\241210-nest-stu\node_modules\@nestjs\core\nest-application.js:173:16)
    at bootstrap (E:\IntellectronSec\Study Project\241210-nest-stu\src\main.ts:7:3) {
  code: 'EACCES',
  errno: -4092,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 3000
}

这个错误表明你的应用程序没有权限监听3000端口。这通常是因为端口已经被其他进程占用,或者你的应用程序没有足够的权限去监听这个端口。

Error: listen EACCES: permission denied 0.0.0.0:3000

解决方案:

  1. 方法一:检查端口占用:使用命令行工具检查3000端口是否已经被其他进程占用。在Linux或Mac上,你可以使用lsof -i :3000netstat -an | grep 3000。在Windows上,你可以使用netstat -ano | findstr 3000

  2. 方法二:更换端口:如果3000端口已经被占用,你可以尝试更改Nest.js应用程序的配置,使用一个不同的端口。你可以在main.ts文件中修改listen方法的参数来更改端口。

    async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.setGlobalPrefix('api');
    await app.listen(3001); // 更改为3001或其他未被占用的端口
    }
  3. 方法三:关闭占用端口的进程:如果找到了占用3000端口的进程,你可以尝试关闭它,或者重新配置该进程以使用不同的端口。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值