Node.js + Mongoose works locally, but not on Heroku
Problem
Here's my node.js file I'm running on Heroku. It works perfectly locally, but when I push it to Heroku, the database collection isn't created and no errors are thrown. Ultimately I'm just trying to get it to actually creating the connection while it's running on Heroku. Thanks.
var mongoose = require('mongoose'),
db_url = process.env.MONGOHQ_URL || "mongodb://john:@staff.mongohq.com:10053/app3305538",
db = mongoose.connect(db_url),
Schema = mongoose.Schema;
//Mongoose DB Test
var MsgSchema = new Schema({
date: {type: Date, default: Date.now},
message: String
});
var MsgModel = db.model("messages", MsgSchema);
var Msg = new MsgModel();
Msg.message = "blurgh";
Msg.save();
Problem courtesy of: Johnathan Croom
Solution
Did you specify node version in heroku?
please refer this. ( I also confused same issue. but resolved.) http://devcenter.heroku.com/articles/nodejs-versions
Solution courtesy of: Takahiro Kubo
Discussion
View additional discussion.