Salam(意思是你好):)
我在我的 Windows 7 机器上开发了一个 node.js 脚本,它运行良好。但是当我在我的 Ubuntu 12.04 上运行它时,会出现以下错误并停止我的应用程序:
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1127:5)
at Object.start (/httpServer/httpServer.js:9:34)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
导致错误的点是这一行中的.listen(80)
:
http.createServer(onRequest).listen(80);
^
我还尝试了一些其他端口号(如 100、300、500 等)而不是 80
,但错误仍然相同。
最佳答案
在 Ubuntu 上,如果没有 root 权限,您将无法监听小于 1024 的端口。尝试在 sudo 下运行 Node 。
sudo node app.js
关于在 Ubuntu 12.04 上使用 http.createServer().listen() 时 Node.js 未处理的 'error' 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19758391/