NestJs: Deploy to Heroku and Add Swagger Docs
Tags: swagger, heroku, nestjs, nodej
Published: 2022-05-23 11:20:39

Hello everyone, we'll be building on the puppies api. I strongly recommend you look at the previous post for the [🐶🐶🐶 puppies api](https://dev.to/drsimplegraffiti/nestjs-puppies-api-k4d).

---

#### Agenda
✅ Add Swagger Documentation
✅ Deploying to Heroku

---


##### Install the swagger docs and the types
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tuwmc5u56oid26mtd1n6.png)
 
---

##### Import the modules inside the main.ts file and configure it
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bijvcbq3gqx42avjddo0.png)
 
---

#### Finally, add the `ApiProperty` to the Entities.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kos0p4qn3hnh770kujxf.png)

---

Let's test our documentation by running `yarn start:dev` and visiting `localhost:7890/api/docs`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/elqtzv2eezduwqlmy45o.png)

---

Just to be sure our application still works, let's get all the puppies created.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/udiimtbdkl4s4we55b5b.png)
 
---

### Heroku Deployment
Login to heroku
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2m0ccwiy2svb2ldkjde.png)

---

#### Create an app
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g27fqkfuqhw2ka1t42ym.png)
 
---

#### Select overview and Configure Add Ons
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5myifgy8n9fo0uktppew.png)

---

#### Search for `Heroku postgres` and click
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vw7oyxqagb1dyzcgcd9o.png)
 
--- 

#### Submit the order form
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khqc49qwh1pz6w8j0zp1.png)

---

#### Click on this to get redirected to the database dashboard
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpxr5hnqs0h9laq2i9gy.png)

---

#### Click on the view credentials
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oei18etm2o5bde5ndy59.png)

---

#### Copy the Database Uri and Head to your `ormconfig.js file`
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jwm0g2tg89pij8v0mx23.png)

---

### orm.config.js
```javascript
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'],
};
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22td9i5imltrx6lgr4n7.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94kr2uafhjza0jer3kb3.png)

---

One last thing to do is to add our env to Heroku's env variable
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjzs4ng53raytjozxnwv.png)

Get the source code [here](https://github.com/drsimplegraffiti/puupies-api).

---

#### Conclusion
I hope this post was helpful. Thanks for reading.