server.address() returns null when providing hostname in server.listen()

545 views
Skip to first unread message

Lothar Pfeiler

unread,
Feb 11, 2012, 4:03:31 AM2/11/12
to nodejs
Hi,

when I use

server.listen(port)

server.address() gives me a nice object with port, family and
hostname.

But when I use

server.listen(port, hostname)

server.address() returns null.

I guess, server.address() uses os libs so here are the platforms where
I tested it:
node v0.6.8 on Linux server 2.6.32-33-server #70-Ubuntu
node v0.6.7 on Mac OS X Lion

Is this already a known bug or is it a feature?

Regards,
Lothar

Ben Noordhuis

unread,
Feb 11, 2012, 8:26:51 AM2/11/12
to nod...@googlegroups.com

It's a documentation bug.

`server.address()` isn't reliable until the 'listening' event is
emitted because Node may need to do a DNS lookup when you pass in a
host name, the results of which aren't immediately available.

I've updated the documentation in d3f6b09.

Lothar Pfeiler

unread,
Feb 11, 2012, 4:54:23 PM2/11/12
to nodejs
Hi Ben,

thanks for the quick reply. That makes sense.

On Feb 11, 2:26 pm, Ben Noordhuis <i...@bnoordhuis.nl> wrote:
Reply all
Reply to author
Forward
0 new messages