When 127.0.0.1 below is omitted app.address() is not null, but when a host is set, it is null.
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);
Error output: TypeError: Cannot read property 'port' of null
Node v0.6.5
I installed express version 2.5.9 - its returning that I have installed 2.5.8 - not sure what that is about.
When 127.0.0.1 below is omitted app.address() is not null, but when a host is set, it is null.
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);
Error output: TypeError: Cannot read property 'port' of null
Node v0.6.5
I installed express version 2.5.9 - its returning that I have installed 2.5.8 - not sure what that is about.
Share Improve this question edited May 24, 2012 at 16:27 Anthony asked May 24, 2012 at 16:02 AnthonyAnthony 2,4113 gold badges21 silver badges26 bronze badges1 Answer
Reset to default 5Because, app.address() is inherited from Node's HTTP module. If you look to the documentation there writes:
Returns the bound address and port of the server as reported by the operating system.
Therefore I assume, when you request a port with an IP, the OS does not report it back to you, so this method returns null. However, when you don't, you may need the IP or address of your puter, since every puter does not have to be "localhost", they can have different domains allow you to only bind sockets to that domain.