Skip to content

Latest commit

History

History
executable file
33 lines (30 loc) 路 2.8 KB

heroku-deployment.md

File metadata and controls

executable file
33 lines (30 loc) 路 2.8 KB

These are some instructions regarding deployment of website on heroku, using local git repository.

SOME IMPORTANT NOTES

  • DO NOT SET PORT AND HOST in .env . Sometimes these override the ones set by heroku and crash the deploy.
  • DO NOT USE HOST ANYWHERE. For local development express app directly binds to localhost, and heroku DOES NOT specify HOST in any env var. THUS the listening function should be like :
    port = process.env.PORT;
    server.listen(port, callback);
    Heroku does not like users specifying host... don't do that.

Now, for deployment, setup the local git branch with required setup.Install heroku CLI globally and setup heroku account.

  1. Setup at least 'build' and 'start' scripts in package.json. The build script should install all dependencies and compile all files. The start script should start the server. NOTE that it is not required to call start from build.heroku itself will first call build, then optimize the files and then call start
  2. run heroku login from shell, which will launch a tab in browser asking to log in to your heroku account. Log in.The the prompt in shell will show message of successful login and shell prompt will return.
  3. Create an app on heroku website from the new App option that is usually on right hand side of 'your apps' tab on heroku website.
  4. Select 'heroku git' option in the deployment options and then setup heroku remote repo on local git repo, using the command given, which will be of type :
    heroku git:remote -a YOUR_APP_NAME
  5. Push your local branch to heroku master branch.Syntax will be :
    git push heroku LOCAL_BRANCH_NAME:master
    In case you want to push the local master branch itself, then
    git push heroku master
    will suffice.
  6. After push is done, in same shell heroku will display the build log, in which you'll see the ongoing status and steps of build.After successful build, it'll also show the deployed website's url and the heroku git repository's url.One can use
    heroku logs and heroku logs --tail to get the logs generated by your app, which are quite helpful to see what went wrong if the app crashes.
  7. Hope that build and deployment goes successful. If any error, find the solution make commit to local repository and start from point 1. If too tired/exhausted, break loop and take a break.
  8. For restarting or stopping the faulty build, heroku build plugin can be helpful :
    heroku plugins:install heroku-builds
    heroku builds:cancel -a YOUR_HEROKU_APP_NAME