Opened 10 years ago

Last modified 10 years ago

#45518 new defect

Nodejs http server doesn't bind to port

Reported by: knightcode (Dylan) Owned by: ci42
Priority: Normal Milestone:
Component: ports Version: 2.3.2
Keywords: yosemite Cc:
Port: nodejs

Description

I've got a Node/Express project with the relevant index.js code below. After upgrading to Mac OS Yosemite and properly following the migration instructions, the 'listen' call of the server fires its callback, which is supposedly called in response to the 'listening' event, but a subsequent 'netstat -a' in another terminal does not show a bound socket on the specified port. I also confirmed that attempting to bind to a port below 1024 without privileged access causes an exception. Above 1024 gets a silent error.... or a false positive really.

var express = require('express');
var http = require('http');

var app = express();

app.set('port', (process.env.PORT || 5000));
// ... set a bunch of other stuff

var server = http.createServer(app);
server.listen(app.get('port'), function () {
  console.log("Node app is running at localhost:%d %d %s", app.get('port'), server.address().port, app.settings.env);
});

Change History (4)

comment:1 Changed 10 years ago by ryandesign (Ryan Carsten Schmidt)

Owner: changed from macports-tickets@… to ciserlohn@…

Your example works fine for me on Yosemite with node v0.10.32 and express@4.9.8.

comment:2 Changed 10 years ago by knightcode (Dylan)

I was running express 4.0.0 installed via npm. I updated to 4.9.8, but still having the same issue. And I'm on node 0.10.32 as well.

I'm going through the migration steps again now that I have XCode 6.1 instead of 6.0.1. And I'm completely wiping /opt/local. Will report back.

comment:3 Changed 10 years ago by knightcode (Dylan)

No change. Still not binding.

comment:4 Changed 10 years ago by knightcode (Dylan)

created another app with just the above code. No luck.

Note: See TracTickets for help on using tickets.