Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js + Mongoose works locally, but not on Heroku

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.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js + Mongoose works locally, but not on Heroku

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×