Skip to content

Instantly share code, notes, and snippets.

@ManishPoduval
Last active April 28, 2021 13:19
Show Gist options
  • Save ManishPoduval/429613d04dc24e29f240c01dad4dbe5a to your computer and use it in GitHub Desktop.
Save ManishPoduval/429613d04dc24e29f240c01dad4dbe5a to your computer and use it in GitHub Desktop.

Deployment with GitHub

To check how to deploy with Heroku-cli read here

  • create heroku account

  • create application

  • Check if the project has these

    • package.json is in the root of the project
    • package.json contains a start script
"scripts": {
  "start": "node server.js"
},

Connect your github repo with heroku

  • Go to the Deploy section in your heroku dashboard

  • Choose Github, and search the repo that you wish to deploy

  • Connect that GitHub repo with your heroku account

  • Enable Automatic deploys. (This will ensure that every time any code is pushed/merged to the master/ main branch, it will automatically deploy to your heroku app)

Go the mongoDB atlas and sign in.

  • When you see these screens, choose the free cluster version

  • Create a new cluster on mongoDB atlas (Please remember your username, password when you create them the first time for your account)
    • Click on connect
    • Allow access from everywhere are create a user with a password (Please make sure you remember these)

  • Choose Connect your application

  • Copy that url that you see

  • That url will look something like this mongodb+srv://manish:<password>@cluster0-st12d.mongodb.net/<dbname>?retryWrites=true&w=majority

  • Change <password> with your real password and <dbname> with the database name you need for your project

  • It will then look like this mongodb+srv://manish:Test@123@cluster0-st12d.mongodb.net/secondProject?retryWrites=true&w=majority

  • copy this mongodb url and save it somewhere

  • configure app

    • Go to your heroku dashboard app page and go to the Settings Tab
    • Add all the envs variable that connect to your Database or any external API's there.
  • To deploy

    • $ git add && $ git commit
    • $ git push origin master
  • If your application isn't deployed successfully do

    • $ heroku logs
    • $ heroku logs -t

You can also share your cluster with other team members so that they can check the data in MongoDB Compass

  • Wile connecting, choose mongoDB Compass
  • Share that url with your password

Ensure you've allowed any website to connect to your database

  • Go to the Network Access tab . Edit the IP whitelist and allow all sites to connect.

Checking for errors

To view error, we'll need to check the logs from heroku and see why it might be crashing.

  • Go to the More section of your app

  • Click on View Logs

  • Read the logs, scroll and analyse what the error is why it might be occurring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment