This guide will walk you through how to deploy a TypeScript-based Node.js backend using the Vercel CLI.
π Folder Structure (Simplified)
Your project directory should look like this:
.
βββ src/
β βββ app/
β β βββ controllers/
β β βββ models/
β β βββ interfaces/
β βββ server.ts
β βββ app.ts
βββ dist/ β Compiled output (after build)
βββ vercel.json
βββ package.json
βββ tsconfig.json
β Prerequisites
- You have a working TypeScript Node.js project.
- TypeScript is properly configured (
tsconfig.json
). - You have a
dist/
directory after building. - You have no errors after building (
npm run build
)
π§ͺ Step 1: Add Build Script
In your package.json
, make sure you have the following scripts:
"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix"
}
Then build the project:
npm run build
This compiles TypeScript into JavaScript inside the dist/
folder.
βοΈ Step 2: Add vercel.json
File
Create a file named vercel.json
at the root of your project with the following content:
{
"version": 2,
"builds": [
{
"src": "dist/server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/server.js"
}
]
}
This config tells Vercel how to build and route requests to your backend.
π¦ Step 3: Install Vercel CLI
If not already installed globally, run:
npm install -g vercel
π Step 4: Login to Vercel
Run:
vercel login
You'll be prompted to log in using GitHub or email.
π Step 5: Deploy to Vercel
Run the deployment command:
vercel --prod
Follow the prompts:
? Set up and deploy βyour-projectβ? (Y/n) β y
? Link to existing project? (y/N) β N
? Whatβs your projectβs name? β library-management-api
? In which directory is your code located? β ./
Vercel will build and deploy your app from the dist/server.js
file.
π Step 6: Access Your Deployed App
Once deployment completes, Vercel will display two URL links, one is inspection link and another one is production link. Choose (ctrl+click
) inspection link. Vercel will show you a domain link.This is your live deployment link. Make sure the link works even in browser incognito mode.
https://library-management-api.vercel.app
π Redeploying
Anytime you make changes:
npm run build
vercel --prod
Top comments (0)