DEV Community

Cover image for NestJs: Deploy to Heroku and Add Swagger Docs
Abayomi Ogunnusi
Abayomi Ogunnusi

Posted on

5 3

NestJs: Deploy to Heroku and Add Swagger Docs

Hello everyone, we'll be building on the puppies api. I strongly recommend you look at the previous post for the 🐢🐢🐢 puppies api.


Agenda

βœ… Add Swagger Documentation
βœ… Deploying to Heroku


Install the swagger docs and the types

Image description


Import the modules inside the main.ts file and configure it

Image description


Finally, add the ApiProperty to the Entities.

Image description


Let's test our documentation by running yarn start:dev and visiting localhost:7890/api/docs
Image description


Just to be sure our application still works, let's get all the puppies created.
Image description


Heroku Deployment

Login to heroku
Image description


Create an app

Image description


Select overview and Configure Add Ons

Image description


Search for Heroku postgres and click

Image description


Submit the order form

Image description


Click on this to get redirected to the database dashboard

Image description


Click on the view credentials

Image description


Copy the Database Uri and Head to your ormconfig.js file

Image description


orm.config.js

require('dotenv').config();

module.exports = {
  url: process.env.DATABASE_URL,
  type: 'postgres',
  ssl: {
    rejectUnauthorized: false,
  },
  autoLoadEntities: true,
  synchronize: true,
  logging: true,
  entities: ['dist/**/*.entity.js'],
};
Enter fullscreen mode Exit fullscreen mode

Of course, you don't want to hardcode your credentials. We store the Database in the .env file and imported in here.

Now for the actual deployment, follow these steps
Image description

Image description


One last thing to do is to add our env to Heroku's env variable
Image description

Get the source code here.


Conclusion

I hope this post was helpful. Thanks for reading.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay