1
votes

I created a new Node.js app on Bluemix this morning and downloaded the boilerplate code. I worked on it locally and then pushed it up. On Bluemix, it refuses to start. The error according to the logs is:

Instance (index 0) failed to start accepting connections

So I Googled for that, in every case where I found the result, the answer was that my application was trying to use a specific port instead of letting Bluemix set it.

Ok, but I'm setting the host/port with the exact code the boilerplate uses:

var appEnv = cfenv.getAppEnv();
// start server on the specified port and binding host
app.listen(appEnv.port, function() {
  // print a message when the server starts listening
  console.log("server starting on " + appEnv.url);
});

So if this is incorrect, it means the code Bluemix told me to download itself is incorrect as well, and I can't imagine that is the issue.

1
Raymond, could you please include here output of "cf logs <app> --recent" for more details?Alex da Silva
That error message can also come if your application simply fails to start. I'd check if you can use "npm start" (or if you passed in a start command, use that) to start your application locally. The code excerpt you've pasted works properly; you can double-check that by simply pushing the original starter code without your changes.Sai Vennam

1 Answers

5
votes

To identify whether cfenv is at fault, I've tested that piece of code with a number of more complex Node.js apps I have, and they work perfectly on Bluemix.

That message can also come when an application you've deployed to Bluemix fails to start at all. Here's a few things you can do to troubleshoot your Node.js application on Bluemix.

  1. Tail logs in another terminal while pushing with "cf logs ". Inspect logs after the failure to see if something failed during the staging process.
  2. Check that your start command in one of two recommended places, scripts.start in package.json or in a Procfile with web: node <start-script>.
  3. Check that your application works locally. First (optional), create a .cfignore file with "/node_modules" in it, so that when you push the app to Bluemix, CF CLI doesn't push your entire folder of node_modules (as they will be installed dynamically). Next, wipe out your node_modules directory and do an npm install --production followed by npm start (or your custom start command). This is what Bluemix does when trying to start your application, so you should double check that it works locally.
  4. Finally, try bumping up your memory, although this is very unlikely that this is why your application fails to start.