Deploy Your API With Vercel
When I started my web development journey, I used to use Heroku to host my API (Application Programming Interface). Heroku has this concept of dyno where your API goes to sleep (idle) after 30 mins if there is no usage. On September 28, 2020 (my birthday), my Heroku account got suspended. So I started to look for alternatives to host my API. The very thing that came to my mind was to buy a VPS, but since I am broke I can’t afford it right now (but I had money to buy $1000 laptop).
Recently, I noticed that one can host their API using Vercel. Vercel is a cloud platform for static sites and server-less Functions. It enables developers to host websites and web services.
So, let me walk you through the guide on how you can host your API on Vercel.
- Create a directory called api, which will contain your API endpoints file.
- Create a new file called vercel.json, and insert the below code
{
"rewrites": [{ "source": "/api/(.*)", "destination": "/api" }]
}
- Push your API code to a Git repository, and then deploy it using Vercel
With just three simple steps you have your API up and running on Vercel for free.
Tip: To run your API locally, run
node api
This is my time writing a guide on doing something so let me how’s it in comments below or on Mastodon.