关于hello_node.js

2012-12-07 13:26:52 +08:00
 leohxj
文件如下
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

运行node hello_node.js后,通过127.0.0.1:8124和localhost:8124均能访问,但是换成本机的固定IP就无法访问。
这是为什么啊?

还有V2EX怎么贴代码。。。。
2716 次点击
所在节点    Node.js
5 条回复
blank_dlh
2012-12-07 13:35:39 +08:00
localhost 解析出来就是 127.0.0.1 ,你绑的 127.0.0.1 当然只能用这个 ip 访问。直接 listen(80) 就可以了。
leohxj
2012-12-07 14:03:21 +08:00
@blank_dlh 谢谢。还有一个问题,我用npm安装express,一直停在npm http GET https://registry.npmjs.org/express,是怎么回事吗?
jackyz
2012-12-07 17:05:40 +08:00
翻墙或者找加速地址。
gratuit
2012-12-07 17:16:17 +08:00
leohxj
2012-12-08 00:14:27 +08:00
@jackyz
@gratuit
谢谢,下午是网络问题。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/54313

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX