![Declarative Programming versus Imperative Programming [Fundamentals and differences between declarative and imperative programming]](/static/0e1ff78966d4f8d96d1891f480fe7e50/144fe/image.jpg)
Deploying an application to Heroku is a straightforward process. Below is a step-by-step guide for deploying a web application to Heroku, whether it’s built with Node.js, Python, PHP, Ruby, Java, or another framework.
Before deploying to Heroku, ensure you have
git --version) git init if needed) Procfile (Defines how to run your app on Heroku)After installing Heroku CLI, log in:
heroku login
This opens a browser for authentication. Once logged in, you can manage your Heroku apps from the command line.
ProcfileA Procfile tells Heroku how to run your app. Create one in the root directory:
For a Node.js app, add:
web: node server.js
For a Python app (Flask/Django):
web: gunicorn app:app
For a React app (Using serve):
web: serve -s build
For other frameworks, adjust accordingly.
package.json or Requirements FileFor Node.js, ensure your package.json includes:
"scripts": {"start": "node server.js"}
For Python, include a requirements.txt with:
Flaskgunicorn
Run pip freeze > requirements.txt to generate dependencies.
Ensure your project is tracked in Git:
git initgit add .git commit -m "Initial commit"
Run:
heroku create your-app-name
If no name is provided, Heroku assigns a random one.
Run:
git remote -v
If Heroku is missing, add it manually:
heroku git:remote -a your-app-name
Deploy your app:
git push heroku main
If using master instead of main:
git push heroku master
Ensure at least one web process is running:
heroku ps:scale web=1
Run:
heroku open
This launches your app in a browser.
If deployment fails, check logs:
heroku logs --tail
Use:
heroku config:set VAR_NAME=value
To view all variables:
heroku config
For PostgreSQL, enable Heroku’s free Postgres addon:
heroku addons:create heroku-postgresql:hobby-dev
Retrieve the database URL:
heroku config | grep DATABASE_URL
Instead of manually pushing, link Heroku to your GitHub repository:
heroku git:remote -a your-app-name
Then, enable automatic deployment from the Heroku dashboard under Deploy → GitHub.
Your app should now be live on Heroku 🎉! You can scale, manage, and monitor it using Heroku CLI or the Heroku dashboard.
Quick Links
![How to deploy a node app in Heroku [Heroku deploy node app, python app, php app, java app]](/static/40f1230d9437529d2319f5c43c1919e6/5e493/heroku.jpg)
