为什么我的 Mac 无法在端口 1000 上运行服务器?

Ore*_*yag 1 macos port backend express

我正在尝试使用 Express.js 运行服务器,每次尝试在端口 1000 上运行它时,我都会收到以下消息:

events.js:292
  throw er; // Unhandled 'error' event
  ^

Error: listen EACCES: permission denied 0.0.0.0:1000
at Server.setupListenHandle [as _listen2] (net.js:1301:21)
at listenInCluster (net.js:1366:12)
at Server.listen (net.js:1452:7)
    at Function.listen (/Users/orensayag/Documents/johnBryce/26 - 210421/hw/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/Users/orensayag/Documents/johnBryce/26 - 210421/hw/index.js:6:5)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Run Code Online (Sandbox Code Playgroud)

在以下位置的服务器实例上发出“错误”事件:在 processTicksAndRejections (internal/process/task_queues.js:80:21) { code: 'EACCES', errno: -13,

  syscall: 'listen',
Run Code Online (Sandbox Code Playgroud)

地址:'0.0.0.0',端口:1000 }

我还听说 Mac 在此端口上运行时存在问题,而在 Windows 中它可以按预期运行。

为什么我的 Mac 无法在端口 1000 上运行服务器?

小智 5

对于低于 1024 的端口,您需要成为 root。您的访问被拒绝,因为启动该进程的用户没有 root 访问权限。