-
Notifications
You must be signed in to change notification settings - Fork 71
Deploying with Heroku
Joseph Alves edited this page May 30, 2015
·
27 revisions
Deployment with Heroku should be streamlined, depending on the functionality and needs of your application. Before attempting to deploy, it is suggested that you read Getting Started with Node.js on Heroku.
To deploy, you should be able to follow these steps.
-
Your project should already be a git project.
-
All listed commands should be run in your project root.
-
If your application requires extra processes or tasks, your mileage may vary.
-
Ensure you have a heroku account authenticated on your machine. Read Getting Started with Node.js on Heroku if you have not already.
-
heroku create
- This will generate a heroku application for your project.
git remote showshould now listherokuas a remote repository for your git project.
heroku config:set NODE_ENV=production
- This command will tell heroku to start your application with an environment variable
NODE_ENVequal toproduction. This is read inserver/env/index.jsin order to select theserver/env/production.jsfile for application information.
heroku config:set SESSION_SECRET=anythingyouwant
- This is the second and last configuration requirement for your application to run. Much like the previous step, this sets the environment variable in your application when heroku runs it. This variable is accessed inside of
server/env/production.js. - Optional: Any other environment variables being used--most likely third-party authentication credentials--need to be set in a similar fashion to the above. Reference the environment variable files.
heroku addons:add mongolab
- This will create a MongoDB instance in the cloud for your application to use while on heroku. This will also set the
MONGOLAB_URIenvironment variable that is referenced inserver/env/production.js. - If you have never used mongolab in the past, you will be asked to enter payment information. You will only be charged if your application makes a lot of queries which is typically the result of high traffic.
git push heroku master
- Ensure you have something to push.
- This will deploy your code to heroku. This will be the way you redeploy your application once changes are made.
- This will likely take a while the first time as
npm installruns for the first time.
heroku open
- Simply opens your application's heroku URL in your browser. It should work! Congrats!
- If it doesn't work:
- Run
heroku configand ensure thatMONGOLAB_URIis set,SESSION_SECRETis set andNODE_ENVis set toproduction. - Make sure your
package.jsonhas the correctstartscript. Heroku uses this command to start your process. - Make sure your
package.jsonhas the correctpostinstallscript. This should resemblegulp buildby default. - Your application may require extra steps to successfully deploy. These extra steps are application-specific and can not be addressed in this walkthrough.
- Run