Monday, March 10, 2014
No Update
Friday, March 7, 2014
Notes: Deploying MEAN Boilerplate to Heroku
Notes: Deploying MEAN Boilerplate to Heroku
Create the Heroku App
heroku create
Push to Heroku
git push heroku master
View the App
heroku open
WTF? Application Error
Mongo is not available.
Setup Mongo
MongoHQ offers free hosting for MongoDBs. Heroku has a free addon for MongoHQ.Add MongoHQ
heroku addons:add mongohq
Heroku wants my credit card before allowing the addon. Um, no.Use MongoHQ with Heroku without a Credit Card
The Heroku addon basically just sets up your HerokuHQ stuff for you. If you want to skip the credit card, you can set it up yourself.Setup MongoHQ
Create a MongoHQ account. Choose the free sandbox version.Once you're set up, find the url to your sweet new db. It looks something like: mongodb://
Create a user for the db through the web interface. I'm sure you can do it from terminal, but you're already here.
Now go to your terminal. :) Verify that you can connect.
mongo troup.mongohq.com:10027/reergymerej -u <user> -p<password>
ormongo troup.mongohq.com:10027/reergymerej
db.auth('dude', 'dude');
Connect Your App
See if you can connect to your MongoHQ db from your local MEAN app.Where do you change the db settings?
/config/env/development.jsChange the db from
localhost
to the url you got above (the one with the username/password in it).db: 'mongodb://dude:dude@troup.mongohq.com:10027/reergymerej',
Welcome to Error Town
/home/grizzle/code/the-runs/node_modules/mongodb/lib/mongodb/connection/base.js:242
throw message;
I know the authentication works since I can connect through the terminal directly. I'm too tired to figure this out tonight.Try, Try Again
The problem was with my copy/paste. In /config/env/development.js, I specifieddb: 'mongodb://dude:dude@troup.mongohq.com:10027/',
instead ofdb: 'mongodb://dude:dude@troup.mongohq.com:10027/reergymerej',
Dur.I tested locally pointing at the remote db and everything's working. I confirmed through the UI and terminal.
mongo troup.mongohq.com:10027/reergymerej
db.auth('dude', 'dude');
db.runs.find().pretty();
Now, let's deploy this sucker. Change db in production
/config/env/production.js
Commit and Push
git add .
git commit -m 'change db config for production'
git push heroku master
This pushes from our local repo to Heroku, not from our Github repo. Changes must be commited to the local git repo before they can be pushed to Heroku.
Around this point, my notes degrade pretty quickly. I changed the production db to the MongoHQ db and kept the dev db pointing at localhost. Heroku deployed alright, but the app wouldn't respond in the browser.
heroku logs
mentioned something about failing to connect to localhost, so I figured the app still thought it was in dev mode. For expediency, I changed the dev db to the remote also, deployed again, and everything started working.Along the way, I noticed there's a MONGOHQ_URL in
/config/env/all.js
. We should probably use that, but lunch breaks are only so long. I chewed up a bit of my time researching how to keep from exposing credentials in Github.Keep Production Credentials off Github
We use git to deploy to Heroku. We also use git to save our code on Github. How can we keep our production credentials in git, available to push to Heroku, but not available to Github?I haven't quite figured it out and that's OK since my username &password are both 'dude' and no one's going to bring down my test db rocking one dyno. It's a good question, though. Here are a couple references I found:
- decent answer using multiple branches
- better, more complex answer from a dude with a high reputation
tl;dr
- Heroku doesn't provide MongoDB.
- Create the db in HerokuHQ.
- Configure MEAN environments to use HerokuHQ.
- Don't push username/password to Github.
References
- http://cogniton-mind.tumblr.com/post/63560840467/howto-gitignore-for-different-branches-update
- http://www.100percentjs.com/deploying-mean-io-to-heroku/
- http://www.elliotbradbury.com/use-mongohq-heroku-without-verifying-account/
- http://support.mongohq.com/common-questions/debugging-connection-issues.html#username-password
Wednesday, March 5, 2014
How to get Bootstrap with Bower
This is a quick post to explain how you can use Bower with your cool new MEAN stack. For this example, we'll install Bootstrap.
Install the Package(s)
bower install bootstrap
OK, all done. No, not really. All we did was download the files. They're not automatically added to our html somehow.
Where does Bower put files?
Out of the box, the MEAN stack puts Bower's files in /public/lib. This is a configuration setting in .bowerrc.
"directory": "public/lib",
How to Use the New Files
The lib directory is public, so we can access them directly. For simplicity, you can add it to /app/views/includes/head.html.
<script src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
What about dependencies?
Dependencies will be installed automatically by Bower. That's one of the main reasons to use a package manager. Boostrap has a dependency on jQuery, so it has been installed as well.
How do you know what dependencies to use?
When you install a package, the dependencies are listed.
bower install bootstrap#3.0.3
bower install jquery#2.1.0
bootstrap#3.0.3 public/lib/bootstrap
└── jquery#2.1.0
You can view all your current packages and their dependencies with
bower list
You can view the dependencies in the package's bower.json file. /public/lib/bootstrap/bower.json shows that bootstrap needs jQuery.
"dependencies": {
"jquery": ">= 1.9.0"
}
Include the dependencies the same way as the main package.
<script src="/lib/jquery/dist/js/jquery.min.js"></script>