gpt4 book ai didi

javascript - 创建一个简单的 Node.js 静态服务器

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:20 24 4
gpt4 key购买 nike

var express = require('express');
var app = express();
app.use('/', express.static('./'));
app.listen(80);

The error msg I receive in the cli via "node server.js" is: events.js:160 throw er; // Unhandled 'error' event ^

Error: listen EACCES 0.0.0.0:80 at Object.exports._errnoException (util.js:1018:11) at exports._exceptionWithHostPort (util.js:1041:20) at Server._listen2 (net.js:1245:19) at listen (net.js:1294:10) at Server.listen (net.js:1390:5) at EventEmitter.listen (G:\angular\node_modules\express\lib\application.js:618:24) at Object. (G:\angular\server.js:4:5) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32)

Any ideas why a simple bit of code would generate errors? I got the code from an older angularjs book I'm trying to learn from. Changes with node or express possibly?

最佳答案

在 Unix 上,所有低于 1024 的端口都称为 Privileged Ports 。只有 root 或其他特定系统用户才能在此处启动服务。

当您使用普通用户进行编程时(您应该这么做),通常会在 1024 以上的端口上启动开发服务器。对于 Web 服务器,通常使用 80803000

错误消息Error: Listen EACCES 0.0.0.0:80也给了你一个提示。 EACCESS 表示您无权在端口 80 上打开服务器。只有 root 用户才能运行生产代码。

还有一条建议:AngularJS 在过去几年里发生了很大变化。所以如果你想学习它,不要使用旧书。您学到的大部分内容可能已经过时并且现在的做法有所不同。

关于javascript - 创建一个简单的 Node.js 静态服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com