node -v
结果是:4.2.1和
npm -v
pi@raspberrypi:~/share/Node $ node Brew-View.js
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EACCES 0.0.0.0:80
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at Server._listen2 (net.js:1221:19)
at listen (net.js:1270:10)
at Server.listen (net.js:1366:5)
at EventEmitter.listen (/home/pi/share/Node/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/pi/share/Node/Brew-View.js:39:8)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
console.log('Hello.');
结果也一样。这听起来像是一个由坏的预装模块引起的问题。但这是一个全新的安装(包括node和raspbian)。有没有一些设置步骤,你必须做具体的节点在pi或调用它不同?
注:这是在π3b上+
编辑:这是我正在运行的代码,它将产生141错误(我已通过npm将ip和express添加到该目录):
const express= require('express')
const ip = require('ip')
const ipAddr=ip.address();
const port=80;
const Server= express();
Server.use(express.static('public'))
Server.get('/',function(req,res){
res.send('<html>'+
'<head>'+
'<meta charset ="UTF-8">'+
'<link rel="stylesheet" type="text/css" href="./main.css"></head><body>'+
'<h1>Brew View</h1>'+
'<p>my IP is: '+ipAddr+":"+port+'</p>'+
'</body>'+
'</html>')
})
// Handle 404
Server.use(function(req, res) {
res.status(404).send('<html>'+
'<head>'+
'<meta charset ="UTF-8">'+
'<link rel="stylesheet" type="text/css" href="./main.css"></head><body>'+
'<h1>404: Page not Found</h1>'+
'</body>'+
'</html>');
});
// Handle 500
Server.use(function(error, req, res, next) {
res.send('500: Internal Server Error', 500);
});
Server.use(express.static('public'))
Server.listen(80,()=> console.log("Hello. Brew View is Hosted at: "+ipAddr+":"+port))
编辑:所以解决方案是没有根用户就不能在80端口上自动托管。