在 Ubuntu 12.04 上使用 http.createServer().listen() 时 Node.js 未处理的 'error' 事件

标签 node.js ubuntu-12.04

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/

相关文章:

ubuntu - 监控并重启服务器上的 Dart 进程

regex - 使用 expect 或 shell 脚本的 Telnet SMTP

Python:导入错误:/usr/local/lib/python2.7/lib-dynload/_io.so: undefined symbol :PyUnicodeUCS2_Replace

ubuntu - 在 ubuntu 中安装 Koha

javascript - 创建对象时是否可以使用 'default' 属性复制 Mongoose 模式中的对象属性?

ubuntu-12.04 - 添加静态 dns 条目

node.js - 找不到模块 'jasmine-reporters'

node.js - checkin node_modules 与 shrinkwrap

node.js - Docker为node、mongo分离容器,如何从node容器填充mongo

node.js - Electron 伪造: missing some dependencies