How to deploy MEAN app on Heroku
MEAN stands for MongoDB , ExpressJS, AngularJS, NodeJs. MEAN is an opinionated fullstack javascript framework - which simplifies and accelerates web application development.
Very first you have to setup local environment with MongoDB and NodeJS. Please check and install NodeJS from www.nodejs.org.
Install MongoDB on your local machine. Due to install MongoDB and NodeJS you’ll need to install HomeBrew first.
Install homebrew
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"Install Node.js by brew
$ brew installNow this is the time to install MongoDB To install the MongoDB binaries, issue the following command in a system shell:
brew updatebrew install mongodbTo build MongoDB from the source files and include SSL support, issue the following from a system shell:
brew install mongodb --with-opensslTo install the latest development release for use in testing and development, issue the following command in a system shell:
brew install mongodb --develNow we’re ready to install MEAN app on your local machine.
To install MEAN app scaffold
$sudo npm install -g meanioNow you can initiliaze your MEAN app
$ mean init myAppMEAN Package install & uninstall
$ mean install package-nameAvailable packages - mean-admin - tokens - translate - ga (Google Analytics) - upload - socket - gmap - comments - crop
usage example
$ mean install mean-adminUninstall package
$ mean uninstall package-nameDelete package
$ mean -d package-nameNOTE: Run Grunt service after your changes to compile your script.
$ grunt serve#Setup Heroku Account
In order to work with Heroku, you also need to download Heroku’s toolbelt (https://toolbelt.heroku.com) which will give you the needed command line tools to communicate with Heroku’s backend. Right after registering in Heroku and installing it’s toolbelt, run the following command and add your SSH key, to identify yourself with Heroku:
$ heroku loginYou’ll need your email address and password for Heroku. Before you push your repo, you need to add public key into your heroku.
Generate the RSA key first by following
$ ssh-keygen -t rsaAdd your key to heroku
$ heroku keys:addRead more about SSH key https://devcenter.heroku.com/articles/keys
Before you go further let’s setup your database on Heroku.
Login to your Heroku dashboard goto Add-ons tab and find MongoHQ under Data Stores. Select free plan and add to your package. Now go to your apps. Select MongoHQ from your app list.
Goto Admin tab (on the left side) and select Users tab on top of the panel. From here you can setup your MongoDM access by adding a user.
Copy your Mongo URI
mongodb://<user>:<password>@linus.mongohq.com:XXXX/appXXXXXXX$ heroku create myAppNow you’re ready to push your code into your Heroku
#Setup your MEAN App config
Very first you have to setup your MongoDB on your config to run your scaffold app.
go to /yourApp/config/env/development.js
find mongodb:localhost
replace with your MongoURI
#Prepare to push Heroku
$ git init
$ git add .
$ git commit -a -m "Fresh start"Now this is a time to push it
$ git push heroku masterNow you can see your project http://yourApp.herokuapp.com
Enjoy playing around
Here is the live example of MEAN app deployed in Heroku http://ariunbolor.herokuapp.com
