A quick start express server deployment guide using Serverless
— Serverless, Vercel, Node.Js, Express.Js — 2 min read
What is Serverless
Serverless refers to a cloud computing execution model in which the cloud provider is responsible for executing a piece of code by dynamically allocating the resources, and the user is only billed for the amount of resources and time actually used. With serverless, the user does not have to provision and manage any servers, making it a more cost-effective and scalable solution for certain types of applications and use cases. Examples of serverless technologies include AWS Lambda, Azure Functions, and Google Cloud Functions.
Pros and Cons of Serverless
Serverless has major pros & cons over normal node server deployment. The table below shows the main pros & cons of serveless:
| Pros | Cons |
|---|---|
| Cost-effective: users only pay for the resources and time they actually use | Cold start : can take longer initial response time, when function/app is first triggered |
| Scalability : Serverless computing can automatically scale to handle large amounts of traffic | With serverless, users have less control to infrastructure and may be limited to customization and configuration of environment |
| Flexibility : it allows developers to focus on writing code, rather than managing and maintaining servers | Serverless computing can have limitations on the amount of memory and execution time available for a given function or application. |
| Low maintenance : requires less maintenance and management as the cloud provider is responsible for infrastructure | Debugging and monitoring apps can be more complex than traditional server |
Basic Express Server
First, let's take a look at very basic Node/Express API server:
import express, { Express, Request, Response } from "express";
const app: Express = express();const port = 1234;
app.get("/", (req: Request, res: Response) => { res.send("Running on Express Server");});
app.listen(port)The Serverless Server Deployment
I am writing this tutorial to focus mainly on Vercel deployment which includes free-tier for personal or non-commercial projects. To deploy the normal server app on Vercel or any other serveless architecture, simply we need to export the application and we are ready to deploy as a serveless.
// ... define express application
// default app export for serverless using Typescriptexport default app;// javascript native exportmodule.exports = app;For more on vercel serverless deployment, I would recommend you to go through Using Express.js with Vercel guide by Vercel.
Conclusion
With this post, you have learned about serverless & serveless deployment on vercel.
Happy Coding!