I am using Node.js Tools for Visual Studio with VS 2015.
When I click run the app (hit the Chrome button with green arrow) my Express server starts listening. However Visual Studio doesn't automatically launch Chrome.
When I open Chrome myself, then I am able to access the Node app.
I wonder if this has something to do with how my bin/www
is configured, but sadly I am not able to find an answer on how to fix this.
Below is bin/www
for my app:
#!/usr/bin/env node
var debug = require('debug')('ExpressApp3');
var app = require('../app');
//app.set('port', process.env.PORT || 3000);
app.set('port', 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
console.log('Express server listening on port ' + server.address().port);
});
P.S. I always want my express server to listen on port 3000.
I updated my bin/www
to listen on process.env.PORT
#!/usr/bin/env node
var debug = require('debug')('ExpressApp3');
var app = require('../app');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
console.log('Express server listening on port ' + server.address().port);
});
But it was causing the Express server to listen on random ports.
Then I accessed Project Properties and added "PORT:3000"
. (I had the Node.js port set to 3000 previously but that was seemingly not making any difference).