DEV Community

Cover image for Deploying a NestJs App with TypeORM & PostgreSQL on Heroku
Bennett(he/him)
Bennett(he/him)

Posted on

1

Deploying a NestJs App with TypeORM & PostgreSQL on Heroku

I recently created a simple full-stack todo app written in Angular for the frontend and NestJs for the backend.

I had to host the app on a live server for testing. I decided to Heroku free dyno that I normally use for hobby apps.

Steps I followed:

  • I personally use the Heroku CLI. So install one if you don't.
  • Login to Heroku via command line
heroku login
Enter fullscreen mode Exit fullscreen mode
  • Create your app on Heroku (This can be done via command line or through the web).
heroku create new-app-devto
Enter fullscreen mode Exit fullscreen mode

Deployment

Setting App the Database

  • Head over to your dashboard at the web interface, then select your app and view resources. From Resources, go down to Add-ons. Search and select your desired Add-on. In our case that will be Heroku Postgres.
  • Select your billing plan and submit your form
  • You'll see that the add-on has been attached as a database.

Connecting your database to your App.

There a few ways to do this, but the most secure is using environmental variables.
We will use the nonsecure direct approach in this article and you can through the official documentation for setting env variables.

  • Click on the navigator toggle icon near your profile icon and select Data. Select your database in the `Datastore and then select Settings. On Database Credentials, click the View Credentials button to reveal the credentials The credentials will be used in your TypeORM database configuration and connect directly to your database in Heroku. An example:-

Add, commit and push changes

  • And after, add and commit all your changes then push to heroku

git push heroku master

  • And your app will be live with a database connection.

Happy Coding.

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay