I am trying to push my angular express web app to bluemix, but I am getting this error
2016-04-05T20:12:50.96-0300 [App/0] OUT > angular-expess-seed-
[email protected] start /home/vcap/app
2016-04-05T20:12:50.96-0300 [App/0] OUT > node app.js
2016-04-05T20:12:51.19-0300 [App/0] OUT Express server listening
on port 3000 in production mode
2016-04-05T20:13:50.37-0300 [DEA/34] ERR Instance (index 0) failed
to start accepting connections
2016-04-05T20:13:50.39-0300 [API/2] OUT App instance exited with
guid b3554c4b-11f5-433f-891e-1df16605df80 payload:
{"cc_partition"=>"default", "droplet"=>"b3554c4b-11f5-433f-891e-
1df16605df80", "version"=>"36d8b569-d38a-465d-8bc6-b14ffd13b413",
"instance"=>"dbd3566e0ef348d9b9f483a32e8fed89", "index"=>0,
"reason"=>"CRASHED", "exit_status"=>-1, "exit_description"=>"failed to
accept connections within health check timeout",
"crash_timestamp"=>1459898030}
2016-04-05T20:13:50.40-0300 [App/0] ERR
2016-04-05T20:14:16.36-0300 [DEA/24] OUT Starting app instance
(index 0) with guid b3554c4b-11f5-433f-891e-1df16605df80
First it was complaining about the start script missing I've fixed that part but no such with this error.
I can see from the error below:
Express server listening
on port 3000 in production mode
that your Node.js application is trying to listen in port 3000. That works in local environment, but for Bluemix you have to get the port from the Cloud Foundry (CF) environment.
Here is a sample code to do that:
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');
// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();
// start server on the specified port and binding host
app.listen(appEnv.port, '0.0.0.0', function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});