Estoy empezando a trabajar con el lado del servidor (node.js) y tengo algunos errores cuando trato de ejecutarlo. Estoy usando 127.0.0.1:80 como servidor, pero estoy experimentando algunos errores cuando trato de ejecutarlo.
Consola:
Server running at http://127.0.0.1:80/ node:events:505 throw er; // Unhandled 'error' event ^ Error: Listen EACCES: permission denied 127.0.0.1:80 //at Server.setupListenHandle [as _listen2] (node:net:1363:21) at listenInCluster (node:net:1428:12) at doListen (node:net:1567:7) at processTicksAndRejections (node:internal/process/task_queues:83:21)// Emitted 'error' event on Server instance at: at emitErrorNT (node:net:1407:8) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'EACCES', errno: -13, syscall: 'listen', address: '127.0.0.1', port: 80 }JavaScript:
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(80, '127.0.0.1'); console.log('Server running at http://127.0.0.1:80/');paquete.json:
{ "name": "test-web-server", "version": "1.0.0", "description": "Node.js test server. Use for whatever bs you want to do", "main": "index.js", "scripts": { "start": "node server.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "PlazL", "license": "ISC" }una regla general es que escuchar puertos inferiores a 1024 a menudo requiere privilegios elevados. Intente cambiar el puerto a 8080 o eleve sus privilegios con sudo.
Para abreviar, aquí está el cambio en su código:
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8080, '127.0.0.1'); // change port here (80 -> 8080) console.log('Server running at http://127.0.0.1:80/');