Skip to content
Itsbohara
Portfolio

A quick start express server deployment guide using Serverless

Serverless, Vercel, Node.Js, Express.Js2 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:

ProsCons
Cost-effective: users only pay for the resources and time they actually useCold start : can take longer initial response time, when function/app is first triggered
Scalability : Serverless computing can automatically scale to handle large amounts of trafficWith 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 serversServerless 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 infrastructureDebugging 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:

server.ts
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.

serverless-server.ts
// ... define express application
// default app export for serverless using Typescript
export default app;
// javascript native export
module.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!