Deploy your NodeJS backend application with Vercel
Prerequisite:
- Active Vercel account (if not create here)
- GitHub account (if not create here)
- NodeJS installed (if not download from here) official documentation recommends having NodeJS version 16 or above.
Let’s create a new Nest JS application
npm install @nestjs/cli
nest new HelloNestJS
Add your newly created project code to GitHub.
And create one file name: vercel.json in your project root folder (where you have your package.json file) and add the below lines and save.
{
"version": 2,
"builds": [
{
"src": "src/main.ts",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/main.ts",
"methods": [
"GET",
"POST",
"PUT",
"DELETE"
]
}
]
}
vercel.json file is vercel custom configuration file used then we deploy our project to vercel.
You can read more configuration options here Configuring Projects with vercel.json
Method 1: Vercel Dashboard
Login to Vercel account and Add New project
In the next page import your git repository and then on next page click on Import
Leave the setting as default and click on Deploy. You will be able to see the live deployment process in action. And in a couple of minutes you will get your live link of your application, Congratulations! You have deployed your Nest JS application with Vercel service and now you are able to test and share with your friends.
Method 2: Command line
We need to install one npm package called vercel. Run below command on command prompt.
npm install -g vercel
Then next run command
vercel .
If you are first time running this command then you must have to run
vercel login
Command and you will be redirected to the login screen of vercel complete the login and visit the command prompt and then run
vercel .
You will be prompting to couple of question, pick the options and hit enter and soon you will get couple of links of your deployed application
One is your main application link and another is you can inspect/monitor your application running logs.
Hooray! you deployed your backend Nest JS application successfully now, test, share your creativity with your friends and enjoy!
My deployed version of application: https://nest-j-scaffold.vercel.app/