Home > OS >  I deployed my app on heroku and I am getting this error on running heroku logs tail "Error conn
I deployed my app on heroku and I am getting this error on running heroku logs tail "Error conn

Time:09-17

I am getting the error because the url in mongoose.connect function is incorrect. What should I put in as the url to connect to the database.

var mongoose = require("mongoose");

mongoose.connect("mongodb://localhost/Blog");

var database = mongoose.connection;

database.on(
  "error",
  console.error.bind(console, "Error connecting to the database")
);

database.once("open", () =>
  console.log("Successfully connected to the database")
);

module.exports = database;

CodePudding user response:

Is a Mongo Database service running on that Heroku machine so that you can access it via localhost? If not, you should install it, otherwise you cannot connect to an non-existent service. Then, check on what port it is running, it is usually localhost:27017.

  • Related