Nodejs App crashed heroku - error failed to connect to localhost:27017

I've been searching for a solution, but anything I've tried gives the same result. I figured it must have something to do with the localhost, but I don't know what's wrong. These are the errors I'm getting when I run heroku logs.

2013-08-05T07:10:34.804131+00:00 heroku[router]: at=error code=H10 desc="App crashed"     method=GET path=/ host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.424107+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.927263+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:20:26.552533+00:00 app[web.1]: Error: failed to connect to [localhost:27017]

My server.js file looks like this.

//create an app server
var express = require('express')
, flash = require('connect-flash')
, helpers = require('view-helpers')
, mongoStore = require('connect-mongo')(express)
, fs = require('fs')    
, mongoose = require('mongoose')
, passport=require('passport')
//create/connect to database
var dbname = 'test';
var uri = 'mongodb://localhost/' + dbname;
mongoose.connect(uri);
console.log('server.js : connecting to %s', uri);
//express settings
var app = express()
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser('keyboard cat' ));
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(express.session({
   secret: 'spoc',
  store: new mongoStore({
    url: 'mongodb://localhost/' + dbname,
    collection : 'sessions'
  })
}))
app.use(passport.initialize());
app.use(passport.session());
app.use(flash())
app.use(helpers('node-beginners')) 
app.use(app.router);
});
//start app
var PORT = process.env.PORT || 3000
app.listen(PORT)
console.log('Express app started on port '+PORT)

//expose app
exports = module.exports = app

I've tried almost everything I could find in other posts, but I still get this error. Please help!

I think your error is related to mongodb instance. To get started with mongodb in Heroku, check their documentation.

To get the correct connection URI, check here

I got the same error app_dir [required] application directory -c [optional] cluster, value [optional]

-d [optional] daemonize process using forever

-p [optional] port, value [required]

[nodemon] app crashed - waiting for file changes before starting...

Solution- even thought dependency were there I had done npm install and then dhcp7641:merchant_center sbell10$ npm install npm WARN package.json Dependency 'grunt-castle' exists in both dependencies and devDependencies, using 'grunt-castle@^0.4.4' from dependencies lazo-mocks@0.1.2 node_modules/lazo-mocks

chai-jquery@1.2.3 node_modules/chai-jquery

and then start working dhcp7641:merchant_center sbell10$ grunt copy-bundle; grunt Running "cpf_app:tempo:merge" (cpf_app) task

Running "copy:cpf" (copy) task Created 8 directories, copied 5465 files

Running "copy:app" (copy) task Created 2 directories, copied 3496 files

Running "merge-conf" task

Running "cpf_app:tempo:bundle-js" (cpf_app) task