1

I using cloud9 ide coding new project. When I deploy on cloudfoundry from cloud9ide. I have error

Application failed to start. Please note that CloudFoundry uses a different port to listen to. When calling 'listen()' use it like '.listen(process.env.PORT || process.env.VCAP_APP_PORT)'.

This is my source

var port = (process.env.VMC_APP_PORT || 3000);

var host = (process.env.VCAP_APP_HOST || 'localhost');

var http = require('http');

var env = process.env.VCAP_SERVICES ? JSON.parse(process.env.VCAP_SERVICES) : null;

var mongodata = env['mongodb-1.8'][0]['credentials'];

http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n' + env); }).listen(port, host);

This source have error when I get mongo object

var mongodata = env['mongodb-1.8'][0]['credentials'];

But not have this line deploy successful

Please help me !!

Thanks so much

user1404596
  • 138
  • 1
  • 5
  • This seems to imply that `VCAP_SERVICES` is not available. Try removing that line. What do you see in the output when you visit the web server? You have `res.end('Hello World\n' + env);`, so you should be able to see whether or not those things are really defined in `env` or not. This looks like it's your doing, so you should know. – Asherah May 19 '12 at 03:15
  • Shouldn't first line be `var port = (process.env.PORT || process.env.VCAP_APP_PORT)` according to the error message? – Farid Nouri Neshat May 19 '12 at 04:30

1 Answers1

0

As the error in the cloud9 console probably tells you (as it tells me when i try this :-) ):

haalasdoallalsakdl (CloudFoundry): [5/6] Crash log
============/logs/stderr.log============
node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property '0' of undefined
    at Object.<anonymous> (/var/vcap/data/dea/apps/haalasdoallalsakdl-0-8be0d413a9ec29a79f665d388ce414bd/app/server.js:7:35)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)

So there is no entry in VCAP_SERVICES called like that. When I console.log the process.env variable, there isn't even any service listed.

So you'll have to install the mongodb service for your app. Fastest to do this is via the CF VMC tools (can't run this in cloud9 at the moment, so you'll have to install this locally):

vmc create-service mongodb --bind your_app_name

Then it'll start up fine.

N.B. You can probably fix this in the .yml file, but I don't know how to do this :-)

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
  • >>vmc create-service mongodb --bind your_app_name when I deploy form local not have error, but when deploy by c9 have same error – user1404596 May 22 '12 at 09:55
  • I just tried this, and when i put the app i'm trying to deploy to from Cloud9 in place of `your_app_name` it works fine. – Jan Jongboom May 22 '12 at 11:19