'NestJS + Heroku - Crashes immediately after a successful build without reason
Procfile
web: npm run start:prod
Package.json
"start:prod": "NODE_ENV=production node dist/main",
Heroku logs
2022-05-10T09:01:50.583126+00:00 app[web.1]: [Nest] 22 - 05/10/2022, 9:01:50 AM LOG [NestApplication] Nest application successfully started +42ms
2022-05-10T09:01:50.818469+00:00 heroku[web.1]: Process exited with status 1
2022-05-10T09:01:50.875464+00:00 heroku[web.1]: State changed from starting to crashed
Everything works fine on local (heroku local and npm run start), but crashes on Heroku. I've tried these before:
- Listen on
process.env.PORT || 8080 - All environments are set (
heroku run printenv) - Set
0.0.0.0/0IP on MongoDB Atlas
These are the environments that Heroku adds:
MEMORY_AVAILABLE=512
PWD=/app
PORT=42675
NODE_ENV=production
NODE_HOME=/app/.heroku/node
LINES=17
HOME=/app
COLUMNS=150
SHLVL=0
WEB_MEMORY=512
WEB_CONCURRENCY=1
PS1=\[\033[01;34m\]\w\[\033[00m\] \[\033[01;32m\]$ \[\033[00m\]
PATH=/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin
DYNO=run.5170
I'm not sure, but could it be for minimum hardware specification?
Solution 1:[1]
The issue was using port 80 for gateway and http-session-affinity was not enabled as it's required for Socket.io. Set process.env.PORT for both HTTP and gateway.
To enable http-session-affinity, run heroku features:enable http-session-affinity
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex |
