简体   繁体   English

node.js linux 上的明确权限错误

[英]node.js express permission error on linux

using arch with admin user account and no sudo on this script:将 arch 与管理员用户帐户一起使用,并且在此脚本上没有 sudo:

var express = require('express');

var fs = require('fs');

var app = express();
app.get('/lol', function(req, res) {
    res.sendFile('second.html', {root: __dirname })
});
var port = process.env.PORT || 81;
var server = app.listen(port);

i get this error that didnt change when i changed the port or the url to trigger it it instantly gives me this error after i run the command: node site.js (the code above is site.js)当我更改端口或 url 触发它时,我得到这个错误并没有改变它在我运行命令后立即给我这个错误:node site.js(上面的代码是 site.js)


    node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied 0.0.0.0:81
    at Server.setupListenHandle [as _listen2] (node:net:1302:21)
    at listenInCluster (node:net:1367:12)
    at Server.listen (node:net:1454:7)
    at Function.listen (/home/{name}/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/{name}/Documents/web/demo/site.js:10:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1346:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EACCES',
  errno: -13,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 81
}

if i run the script with sudo it works fine but i dont want to run it in sudo beacuse i have to run it on a server with no sudo.如果我用 sudo 运行脚本它工作正常但我不想在 sudo 中运行它因为我必须在没有 sudo 的服务器上运行它。 any help?有帮助吗?

Using port below 1024 without root permission is common issue.在没有 root 权限的情况下使用低于 1024 的端口是常见问题。 Try port bigger than 1024.尝试大于 1024 的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM