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

2
  • 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. Commented May 19, 2012 at 3:15
  • Shouldn't first line be var port = (process.env.PORT || process.env.VCAP_APP_PORT) according to the error message? Commented May 19, 2012 at 4:30

1 Answer 1

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 :-)

Sign up to request clarification or add additional context in comments.

2 Comments

>>vmc create-service mongodb --bind your_app_name when I deploy form local not have error, but when deploy by c9 have same error
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.