Migrating Node.js app from Heroku to Fly.io
April 1, 2023I recently migrated the Node.js app from Heroku to Fly.io, mainly due to reduced costs.
This blog post will cover the necessary steps in the migration process.
Prerequisites
Heroku app running
Use the exact versions for dependencies and dev dependencies in package.json so installation and build steps can pass successfully
Use the same Node.js version in Dockerfile, package.json, and GitHub Actions workflow
Use API gateway or custom domain for the service so web apps and mobile apps don't get affected by changing the URL of the service
Migration steps
Migrate environment variables and secrets
Migrate the Postgres database with the following commands (the
ssl
field in database configuration options is not needed)
fly secrets set HEROKU_DATABASE_URL=$(heroku config:get DATABASE_URL)fly ssh consoleapt update && apt install postgresql-clientpg_dump -Fc --no-acl --no-owner -d $HEROKU_DATABASE_URL | pg_restore --verbose --clean --no-acl --no-owner -d $DATABASE_URLexitfly secrets unset HEROKU_DATABASE_URL
Migrate the Redis database if it's used
Include the deployment step in the GitHub Actions workflow
Course
Build your SaaS in 2 weeks - Start Now