DEV Community

Cover image for Deploy NestJS typescript app to Heroku (Solved: 503 Error)

Deploy NestJS typescript app to Heroku (Solved: 503 Error)

Rosy Shrestha on February 27, 2021

Deploying applications on Heroku is pretty straightforward in most cases. But I ran into a problem while deploying my NestJS application that inclu...
Collapse
 
lazaroofarrill profile image
Lazaro O'Farrill • Edited

Great article, just wanted to point out that step 6 is not correct. That is what you would do if you didn't go through step 5. If you setup the Procfile to run start:prod you don't need development dependencies.

Collapse
 
rosyshrestha profile image
Rosy Shrestha

Thanks for the feedback !

Collapse
 
bastiw profile image
Sebastian Weiß

Thanks a log :)

I am using it with fastify and I was required to add process.env.HOST to the listen too. Something like

const port = process.env.PORT ?? 3000;
const host = process.env.HOST || '0.0.0.0';

.....
await app.listen(port, host);

Enter fullscreen mode Exit fullscreen mode
Collapse
 
emiperalta profile image
Emiliano Peralta

Thanks!

Collapse
 
saeed_sharman profile image
Md Saeed Sharman

I did not change the NPM_CONFIG_PRODUCTION flag but added required depenencies and was able to deploy successfully.

"dependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/axios": "0.0.3",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
"@types/cache-manager": "^3.4.2",
"@types/express": "^4.17.13",
"@types/node": "^16.0.0",
"cache-manager": "^3.6.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},

Collapse
 
nilsjansen profile image
Nils Jansen

Great post! I was looking for a solution to this for way too long. Most tutorials say "just include /dist in the git repository" which really messes things up when trying to merge branches etc. :D

Collapse
 
rosyshrestha profile image
Rosy Shrestha

Thank you @nilsjansen :D I had to go through many resources to come to a solution. I thought it was just me.
Glad this helped you :)

Collapse
 
sinxwal profile image
Sergio Tskhovrebov

Great job!

Collapse
 
nachocapodanno profile image
Nacho Capodanno

Thanks dude! Great info!! Very Helpful @ @nilsjansen

Collapse
 
cloudkungfu profile image
Javel Rowe

This was super handy! Thanks much

Collapse
 
sabopriest profile image
PRIEST SABO

Thanks for this

Collapse
 
andres_arcila_c4de0c8a556 profile image
Andres Arcila

U help me Thanks !!

Collapse
 
laakhey profile image
Bikash Shrestha

Thanks! this helped a lot.

Collapse
 
justin_m_morgan profile image
Justin Morgan

In point 6 (devDependencies), what devDependencies were required (or should be moved to "dependencies")?

Collapse
 
rosyshrestha profile image
Rosy Shrestha

As far as I remember, for me they were dependencies like some of the typescript packages.

Collapse
 
karkipy profile image
Aashish Karki

ayyyy thank you for this

Collapse
 
kimkyeseung profile image
Kim Kyeseung

Interesting! but how distinguish dev and prod environment??