How to deploy a Nodejs server in Vercel | Node JS backend
How to deploy Node JS backend on Vercel
What is Vercel?
Vercel is an American-based cloud platform company. Vercel provides a platform that enables its users to host their static as well as dynamic websites. Vercel is free to use and it is always up. Vercel manages deployment through the Git repositories as it is directly linked to the Git accounts of the user.
You may also like:
Prerequisite:
- A Git hub account.
- A Vercel account (linked with the git account).
Note: This article only explains, how to deploy node js serve to vercel i.e., only the backend, for the frontend part, there will be another article, explaining the same, so please follow the other article as well because the frontend will be hosted on firebase and it is developed in react.
How to host a node js backend on Vercel
Note: In order to deploy a node server on vercel, please add a file named vercel.json to your server's root directory. Inside the vercel.json file mentioned the below lines of code.
{
"version": 2,
"builds": [
{
"src": "./app.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/.*",
"dest": "app.js"
}
]
}
After you have created the file and written the following code, commit it and push it onto your git repository and follow the instruction given below.
- Open your vercel account overview page and click on the Add new button and select the Project option.
- On the second page click on the continue with GitHub option.
- Now search for the git repository in which you have your node js server and click on the import button.
- On the project configuration page, give a unique name to your project. For node js, leave the framework preset to others and finally give the root directory path by clicking the edit button.
- If you have a two-folder structure (like frontend and backend, client and server, etc) choose the one that consists of the node js project as the root directory (in my case it is the backend).
- Finally, click on the deploy button to deploy your node js project. If everything goes right, within a few seconds your project will be live.
- Now click on the continue to dashboard button.
- On the production deployment page, you will find all the information regarding your project with the link (domain) through which you can see your project live. You can copy the link to use on your front end side so that your front end can communicate with your back end.
Note: Deployment of Node js server ends here. See how to host react frontend from here.
How to host Node js server on Vercel
Note: This is only the first part (backend on Vercel), the second part (frontend on Firebase) build with react is available in another article and video, so please visit that one also for the complete information on how to host a single project on two different platforms and join them together and use as a single project.
This is how you can deploy a node js backend (server) on Vercel.
I hope this article was helpful to you.
Thank you.

Comments
Post a Comment