English 中文(简体)
当 HOST 设置在 AP. listen (PORT, HOST) 中时, AP. address () 为何无效?
原标题:How come app.address() is null when HOST is set in app.listen(PORT, HOST);

当以下127.0.0.1被省略 ap.address () 不是无效的, 但当设置主机时, 它就是无效的 。

var express = require( express ),
    app = express.createServer();

app.use(express.logger());

app.get( / , function(req, res){
    res.send( Hello World );
});

app.listen(3000,  127.0.0.1 );
console.log(app.address());
console.log( Express server started on port %s , app.address().port);

错误输出: TypeError: 无法读取 null 的属性端口

节点v0.6.5

我安装了快件2.5.9 - 它的返回,我安装了2.5.8 - 不知道这是什么

最佳回答

因为, app. address () 是从节点 s HTTP 模块继承的。 如果您查看 < a href=" http://nodejs.org/docs/latest/ api/ net. html# net_ server_ address" rel=" noreferr" > 文件 , 它写道 :

Returns the bound address and port of the server as reported by the operating system.

因此,我假设,当您申请带有 IP 的端口时, 操作系统不会向您报告, 所以此方法返回无效 。 但是, 如果您不这样做, 您可能需要您的计算机的 IP 或地址, 因为每个计算机都不必是“ 本地主机 ”, 他们可以拥有不同的区域, 允许您只将连接到此域 。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签