Currently, I have this config section to run with Heroku's mlab, or locally if it's in development
var env = process.env.NODE_ENV || 'development';
if (env === 'development') {
process.env.PORT = 3000;
process.env.MONGODB_URI = 'mongodb://localhost:27017/manage';
} else if (env === 'test') {
process.env.PORT = 3000;
process.env.MONGODB_URI = 'mongodb://localhost:27017/manage-test';
}
which is working for the authentication section of my code. However, I have to access another collection within that database, and currently, I'm connecting it locally with
app.get('/auth-home', isLoggedIn, (req, res) => {
MongoClient.connect("mongodb://localhost:27017/manage", (err, db) => {
db.collection("home", (err, collection) => {
collection.find().toArray((err, result) => {
if (err) {
return err;
}
});
});
});
});
However, this won't connect with mlab since it's localhost. So my issue right now is that I'm not sure how to pass that config section of code into my routes as well as connecting to a different collection, and then having it work with Heroku as well.