I have a Node.js app using Express that stores data in a mongoDB (locally).
It's now pushed to heroku successfully on a cedar stack and the server is running. I added the mongohq addon through the terminal.
Now... how do I connect that mongoDB through mongohq to my application to start using it??? I don't see a tutorial for this anywhere online. If you can point me to one or get me started on where to add the configuration, I would greatly appreciate!
Thanks much.
Update:
I've tried the following (with real values for MYPASSWORD and MYDBNUMBER:
in routes.js
var db = mongoose.connect('mongodb://heroku:<MYPASSWORD>#staff.mongohq.com:10049/<MYDBNUMBER>');
in my schema.js (also tried using the heroku
var mongoose = require('mongoose');
mongoose.connect('mongodb://heroku:<MYPASSWORD>#staff.mongohq.com:10049/<MYDBNUMBER>');
my package.json
{
"name": "NAME"
, "version": "0.0.1"
, "dependencies": {
"express": "2.4.6"
, "connect": "1.7.1"
, "stylus": ">= 0.0.1"
, "mongodb": ">= 0.9.6-7"
, "mongoose": ">= 2.0.0"
, "ejs": ">=0.4.3"
}
}
Right now, only the root '/' GET is successful. Actually, if I try /page/ANYTHING I can successfully get a rendered 500 Error page that I made to handle attempts to get 'pages' that haven't been created... That seems kind of weird to me. Everything else gives me an Internal Server Error.
ALSO, if i go to mongohq and open my database there, a collection for my model pages has been created and the indexes for uniqueness have been created, even tho I haven't been able to access the pages to create or view the model in my app...
happy to provide any other info... so stuck.
We are using heroku against MongoHQ but in our case we created the MongoHQ account on our own so our solution is a bit different.
Now, we are using the Redis plugin and in that case we connect to Redis using the heroku env variables.
When you create a new plugin, Heroku adds a bunch of env variables that you can access from your node.js app easily doing this:
process.env.NAME_OF_VAR
In the case of Redis to go the name of the var is REDISTOGO_URL so our code looks like
process.env.REDISTOGO_URL
For MongoHQ the env variable seems to be MONGOHQ_URL
You may need to do some parsing. Heroku have some documentation for Ruby here http://devcenter.heroku.com/articles/mongohq#using_the_mongo_ruby_driver that should help you to get it going.
With respect to where to do this in an express app. We are doing all the setup on app.js that is our entry point in the app.
Hope this helps.
Related
I developed a FastAPI app in a Virtual Environment using an SQLite database but deployed it on Heroku with a PostgresSQL database on Heroku as suggested in the tutorial. Although it worked on my PC, adding PostegresSQL as an addon & replacing the value of SQLALCHEMY_DATABASE_URL in the database.py broke everything. Note that I've properly frozen the dependencies on the requirements.txt file. Yet I can't figure out what went wrong.
For further clarification, I've pushed my code to GitHub & it can be accessed at this repository - Self_calculation.
If you are using Postgres Addon on Heroku, probably your solution is simple.
Use os.environ to get the connection parameters , don't try to connect directly, it's Heroku's recommended solution from Heroku Postgres
import os
DATABASE_URL = os.environ.get('DATABASE_URL')
I just need to run this:
1)heroku git:remote -a my_heroku_app_name
2)heroku logs --tail
after that I could see my problem.
In my case I forgot to change postgres url in alembic.ini file
I built and deployed a Node.js Postgres app to Heroku and can not get to any of my endpoints via the Heroku site except the root GET route. Curiously, when I run Heroku local web ALL my endpoints behave exactly as they should. I can successfully perform CRUD on the app running via Heroku local web. However, when I try, for instance, to create a user using the Heroku URL, it returns an empty error message. Yet, when I check the associated database I find that the user was indeed created. Other than returning an empty error message when I try to either create a user or sign it, the app correctly responds with the different errors I programmed. For example, when I tweak my login details or try to register the same user I earlier tried to register it correctly says the user already exists!. Still, when I try to log in that same existing user I get a blank error message. Note that I created both the Heroku PostgreSQL database and my local PostgreSQL database from exactly the same queries. Please, can you help me through this bottleneck? I am using Postman to test my APIs.
Test to sign in user on Heroku app running on the local machine: success!
Same exact test with Heroku URL: cryptic error.
Ok, so after a lot of researching and fiddling around I discovered the solution. I did not add keys from my .env file to Heroku as config vars found under the settings tab of the Heroku User dashboard. Manually adding my environment variables resolved the matter. Now my app is working both on my local machine and via the Heroku URL.
I was trying to get the DM Dashboard working on my Ubuntu 16.04. You can find it here: https://github.com/dm-dashboard/dashboard
I already installed Git, MongoDB, Node, Mean.io and Forever. I'm new to working with all of the things, including Git. There are two things I don't understand:
In the instructions you can find this:
Before we start the server, we will need to configure it for your environment
To Configure
Change to the checkout folder
Open config/env/development.json
Update the "db" property to point to your mongo DB
Save and close the file
When opening the development.js the part where "db" is foud says:
module.exports = {
db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost') + '/dashboard',
debug: true,
// aggregate: 'whatever that is not false, because boolean false value turns aggregation off', //false
aggregate: false,
mongoose: {
debug: false
},
Now what do I have to change to what? I don't know where my MongoDB is.
To open the Dashboard in a browser the instruction says:
Open your browser and navigate to
http://[path_to_where_you_deployed]:3000
What does "path_where_you_deployed" mean?
I feel like the solution is very simple, but I just can't figure out what to do.
I really appreciate you help!
db should be your Mongo DB URI
[path_to_where_you_deployed] will we where you spin up this server, such as 127.0.0.1 if you're running locally for dev... or a heroku url if you deploy there
I'm learning how to set up a server on OpenShift that uses node, express, GraphQL and Postgres and I need some help.
When trying to set up the GraphQL Server I've been following this and it works on my local machine:
import Express from 'express';
import GraphQL from 'express-graphql';
import Schema from './db/GQLschema';
const app = Express();
app.use('/graphql', GraphQL({
schema: Schema,
pretty: true,
graphiql: true
}));
...
I'm using the server.js template provided by OpenShift so the above changes to:
...
self.app = express();
self.app.configure(function() {
self.app.use('/public', express.static(__dirname+'/public'));
self.app.use('/graphql', GraphQL({
schema: Schema,
pretty: true,
graphiql: true
}));
});
...
But this doesn't work when pushed up to OpenShift. I get 'Internal Server Error' instead of the graphiql interface.
I'm new to this, but here are some guesses as to what it might have to do with:
Connecting to database
Missing dependencies
Connecting to database: I have 2 json config files. One for my local machine which is connected using a port-forward SSH tunnel to OpenShift. That works fine. The other is one for production. In it I have all the strings for the database name, user, port, host, and password, that OpenShift provided me. I'm using the config library which looks at NODE_ENV to decide which config json file to use. I set the NODE_ENV variable on OpenShift to production. When I query it, it shows all the correct strings. Is there something else I need to set?
Missing dependencies: To keep it neat, I am keeping my back-end code separate from my front-end code. So the back-end code has only the express, graphql, sequelize, config, and pg stuff installed. Do I need something else to make the graphiql page work? Also, I put all the /node_modules/ in the .gitignore file -- I assumed that OpenShift installs them post push. Was that the right thing to do?
Would appreciate any help!
OK - I solved it by doing the following:
in the openshift cli tools turn on error logs
rhc tail -a <yourappname>
This will give you some clues. In my case it was a message from express-graphql "unresolved promise". After researching I found that if you install and save es-promise and add this line to the top of the server.js file:
require ('es6-promise').polyfill();
Hope that helps someone else!
I'm trying to get a new/blank volt (0.9.5) app into production on Heroku following the instructions on the Volt docs page.
The application deploys successfully until I try and add the Mongo database.
The below creates a new MongoLab database and sets a connection URI to the MONGOLAB_URI variable.
$ heroku addons:create mongolab
I thought all I had to do was copy the below into my config/app.rb file and replace the 'MONGOHQ_URL' with 'MONGOLAB_URI'.
config.db_driver = 'mongo'
config.db_name = (config.app_name + '_' + Volt.env.to_s)
if ENV['MONGOHQ_URL'].present?
config.db_uri = ENV['MONGOHQ_URL'] # you will have to set this on heroku
else
config.db_host = 'localhost'
config.db_port = 27017
end
But this is resulting in an application error and the log is showing the below...
[ERROR] Error adding listener: #<Mongo::AuthenticationError: Failed to authenticate user
Can anyone point me in the right direction?
Some other users suggested that the issue was to do with an outdated version of the volt-mongo gem which was, "using an old version of the Mongo Ruby driver." I have since upgraded to the latest version (currently 0.1.4) and everything seems to be working ok with the database.
This isn't an answer, but you should be able to run heroku config to see what ENV's are set for the dyno. Does that show the ENV?