-
Notifications
You must be signed in to change notification settings - Fork 72
Deploying with Heroku
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 show
should now listheroku
as 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_ENV
equal toproduction
. This is read inserver/env/index.js
in order to select theserver/env/production.js
file 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:create heroku-postgresql:hobby-dev
- This will also set the
DATABASE_URL
environment variable. -
IMPORTANT - for 1607, your
server/env/production.js
currently checksprocess.env.DATABASE_URI
for the location of the database url, but Heroku-Postgres creates theDATABASE_URL
variable instead. You will need to change the stringprocess.env.DATABASE_URI
toprocess.env.DATABASE_URL
— keep everything else, including the keyDATABASE_URI:
, the same.
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 install
runs 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 config
and ensure thatDATABASE_URL
is set,SESSION_SECRET
is set andNODE_ENV
is set toproduction
. - Make sure your
package.json
has the correctstart
script. Heroku uses this command to start your process. - Make sure your
package.json
has the correctpostinstall
script. This should resemblegulp build
by 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
Once you've deployed, you can re-deploy in the future easily via git push heroku master
. But why not take things a step further and enable continuous integration with automated deployment?