using arch with admin user account and no sudo on this script:
JavaScript
x
11
11
1
var express = require('express');
2
3
var fs = require('fs');
4
5
var app = express();
6
app.get('/lol', function(req, res) {
7
res.sendFile('second.html', {root: __dirname })
8
});
9
var port = process.env.PORT || 81;
10
var server = app.listen(port);
11
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)
JavaScript
1
25
25
1
node:events:371
2
throw er; // Unhandled 'error' event
3
^
4
5
Error: listen EACCES: permission denied 0.0.0.0:81
6
at Server.setupListenHandle [as _listen2] (node:net:1302:21)
7
at listenInCluster (node:net:1367:12)
8
at Server.listen (node:net:1454:7)
9
at Function.listen (/home/{name}/node_modules/express/lib/application.js:618:24)
10
at Object.<anonymous> (/home/{name}/Documents/web/demo/site.js:10:18)
11
at Module._compile (node:internal/modules/cjs/loader:1101:14)
12
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
13
at Module.load (node:internal/modules/cjs/loader:981:32)
14
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
15
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
16
Emitted 'error' event on Server instance at:
17
at emitErrorNT (node:net:1346:8)
18
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
19
code: 'EACCES',
20
errno: -13,
21
syscall: 'listen',
22
address: '0.0.0.0',
23
port: 81
24
}
25
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. any help?
Advertisement
Answer
Using port below 1024 without root permission is common issue. Try port bigger than 1024.