leohxj
V2EX  ›  Node.js

关于hello_node.js

  •  
  •   leohxj · Dec 7, 2012 · 3600 views
    This topic created in 4919 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
        1
    blank_dlh  
       Dec 7, 2012
    localhost 解析出来就是 127.0.0.1 ,你绑的 127.0.0.1 当然只能用这个 ip 访问。直接 listen(80) 就可以了。
    leohxj
        2
    leohxj  
    OP
       Dec 7, 2012
    @blank_dlh 谢谢。还有一个问题,我用npm安装express,一直停在npm http GET https://registry.npmjs.org/express,是怎么回事吗?
    jackyz
        3
    jackyz  
       Dec 7, 2012
    翻墙或者找加速地址。
    gratuit
        4
    gratuit  
       Dec 7, 2012
    leohxj
        5
    leohxj  
    OP
       Dec 8, 2012
    @jackyz
    @gratuit
    谢谢,下午是网络问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1357 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 23:55 · PVG 07:55 · LAX 16:55 · JFK 19:55
    ♥ Do have faith in what you're doing.