Migrate from Heroku to Vercel
Now that Heroku has stopped its free-tier plan, it's time to move my Angular projects to another platform.
25th November 2022
Time to read: 1 min
Deprecation of Heroku free resources
Starting November 28, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis® plans will no longer be available. We will begin to scale down existing dynos and delete databases with free plans on this date. You also can’t provision new dynos or databases on free plans.
With a few Angular projects hosted on Heroku, I needed to find a free and fast alternative. I decided on Vercel.
Vercel
Vercel Inc., formerly Zeit, is an American cloud platform as a service company. The company maintains the Next.js web development framework. Vercel's architecture is built around Jamstack, and deployments are handled through Git repositories.
Steps to migrate
In the project folder:
- Delete
Procfile
- Update package.json. Replace
"start:heroku": "node dist/PROJECT_NAME/server/main"
, with"vercel-build": "npm run build:ssr"
- In project root create a new directory:
api
. In this folder createindex.js
and add this code:
const server = require('../dist/PROJECT_NAME/server/main');
module.exports = server.app();
- In project root, create
vercel.json
and add this code:
{
"version": 2,
"public": true,
"name": "test-universal",
"rewrites": [
{ "source": "/(.*)", "destination": "/api" }
],
"functions": {
"api/index.js": {
"includeFiles": "dist/PROJECT_NAME/browser/**"
}
}
}
In the project folder, open terminal window:
git remote rm heroku
git init
git remote add origin https://github.com/GIT_NAME-git/REPO.git
git branch -M main
git push -u origin main
Open your Vercel dashboard and import the Git repository into Vercel.
Result
Vercel will build and deploy your project if no errors. I had one error which was fixed by changing Node version to 14x
in project settings.
Mumble