当我运行我的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
解决方案:
-
方法一:检查端口占用:使用命令行工具检查3000端口是否已经被其他进程占用。在Linux或Mac上,你可以使用
lsof -i :3000
或netstat -an | grep 3000
。在Windows上,你可以使用netstat -ano | findstr 3000
。 -
方法二:更换端口:如果3000端口已经被占用,你可以尝试更改Nest.js应用程序的配置,使用一个不同的端口。你可以在
main.ts
文件中修改listen
方法的参数来更改端口。async function bootstrap() { const app = await NestFactory.create(AppModule); app.setGlobalPrefix('api'); await app.listen(3001); // 更改为3001或其他未被占用的端口 }
-
方法三:关闭占用端口的进程:如果找到了占用3000端口的进程,你可以尝试关闭它,或者重新配置该进程以使用不同的端口。