Looking for a serverless hosting service is a big pain when you just want to taste or even host a small project on it. Today, I found a new resource which lets you create serverless functions for absolutely free! Vercel. So, lets build & deploy our first Serverless function on it!
The platform requires us to install its CLI in order to develop & deploy our functions. Lets do
npm i -g vercel to install the CLI globally. After creating a new directory, we'll initialize it as a new node project.
Vercel cli expects us to put all of our
.js files in a folder called
.js files will contain 1 default exported function which represents a REST API endpoint taking 2 parameters
response representing the express's
Response objects respectively (just like in normal
express.js GET/POST endpoints).
The url at which the endpoints will be hosted will be
"But how I will develop them without even testing?"
The vercel cli which we just just installed globally provides a functionality to run the functions on our own local machines.
You will be required by the CLI to login/signup into a vercel account, join me from here after completing that ;)
Now, to run them, we must do
vercel dev. For the first time running the cli, it requires us to do some quick configs & settings, after completing that you should see something like this:
To check how the functions are working locally, we have to go to
http://localhost:3000/api & to access the endpoint in
hello.js, we will go to
Everything looks awesome! lets deploy it on vercel!
You can check limits for a free plan set by the platform here.