leohxj
V2EX  ›  Node.js

关于hello_node.js

  •  
  •   leohxj · Dec 7, 2012 · 3930 views
    This topic created in 5095 days ago, the information mentioned may be changed or developed.
    文件如下
    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怎么贴代码。。。。
    5 replies  •  1970-01-01 08:00:00 +08:00
    blank_dlh
    blank_dlh
    Dec 7, 2012
    1
    localhost 解析出来就是 127.0.0.1 ,你绑的 127.0.0.1 当然只能用这个 ip 访问。直接 listen(80) 就可以了。
    leohxj
    leohxj
    OP
    Dec 7, 2012
    2
    @blank_dlh 谢谢。还有一个问题,我用npm安装express,一直停在npm http GET https://registry.npmjs.org/express,是怎么回事吗?
    jackyz
    jackyz
    Dec 7, 2012
    3
    翻墙或者找加速地址。
    gratuit
    gratuit
    Dec 7, 2012
    4
    leohxj
    leohxj
    OP
    Dec 8, 2012
    5
    @jackyz
    @gratuit
    谢谢,下午是网络问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2336 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:42 · PVG 21:42 · LAX 05:42 · JFK 08:42
    ♥ Do have faith in what you're doing.