How to deploy MERN application on Vercel ?
Last Updated :
16 Oct, 2023
Vercel is a platform that caters to front-end developers by providing fast and dependable infrastructure to support the creation of innovative designs. With their services, teams can efficiently develop, preview, and deploy user-friendly interfaces. They offer support for over 35 front-end frameworks and seamlessly integrate with various headless content, commerce, and database options. Their platform has zero configuration requirements, making it hassle-free for developers to use.
Features of Vercel
- Deploy your Project with automatic CI/CD.
- Get a Preview Deployment for every git push.
- Host your Node.js backend using their platform.
- Monitor your application performance over time with Vercel Analytics.
- Update content without redeploying.
- Improve the loading performance of your images.
- Serve content as fast as possible.
Steps to Deploy the MERN App on Vercel
Mern is a combination of front-end and back-end servers for the full-stack application. So to deploy the MERN application on Vercel it will be done in two parts i.e.,
Part 1: Deploying Backend made in Node JS for your MERN application
Step 1: Add the given vercel.json file in your backend directory first: Adding this file will enable Vercel configuration.
vercel.json fileStep 2: Deploy server-side i.e backend of your MERN app: Go to Vercel dashboard and click on the "Add New..." button and select the "Project" category.
Add New... buttonStep 3: Import Your Git repository after linking your Github/Gitlab/BitBucket account with Vercel:
Importing Git RepositoryStep 4: Configure the Node.js backend of your MERN app:
- Write your project name. For eg. my-project-backend
- Select "Other" in the framework option. This will ensure that the setup and customization process will be specific to Node.js.
- Choose the backend directory of your project where the build command will be run by Vercel.
- Add your environmental variables. For eg. MONGO_ATLAS_URL: my-mongo-atlas-url
- Click on the "Deploy" button.
Backend ConfigurationCongratulations! Your backend will be up and running within a minute after deployment.
Note: Don't forget to save the deployment link of your server and replace it in your code wherever the local server link was provided.
Part 2: Deploying Frontend made with React JS for your MERN application
Note: Step 1 and Step 2 are the same as Step 2 and Step 3 as discussed above respectively.
Step 1: Deploying the front end of your MERN app: Go to the Vercel dashboard and click on the "Add New..." button and select the "Project" category.
Step 2: Import Your Git repository after linking your Github/Gitlab/BitBucket account with Vercel:
Step 3: Configure the Node.js backend of your MERN app:
- Write your project name. For eg. my-project
- Select "Create-React-App" in the framework option. This will ensure that the setup and customization process will be specific to React.js.
- Choose the backend directory of your project where the build command will be run by Vercel.
- Add your environmental variables. For eg. API_KEY: my-api-key
- Note: One mandatory environmental variable is GENERATE_SOURCEMAP: false for security and performance reasons.
- Click on the "Deploy" button.
Frontend ConfigurationCongratulations! Your frontend will be up and running within a minute after deployment.
Enable Vercel Analytics: Vercel Analytics provides valuable insights to developers by allowing them to monitor the number of visitors, page views, location of visitors, and devices used to access their website. This information enables developers to track the traffic their site is generating and make informed decisions to enhance their website's performance.
Vercel AnalyticsStep 1: Enable Audiences in Vercel Analytics: On the Vercel dashboard, select your Project and then click the Analytics tab. From there, select the Audiences tab, and click Enable from the dialog.
Step 2: Add `@vercel/analytics` to your project: Using the package manager of your choice, add the @vercel/analytics package to your project:
- Using npm: npm i @vercel/analytics
- Using yarn: yarn add @vercel/analytics
Step 3: Call the `inject` function in your app: Add the following code to your main app file:
import { inject } from '@vercel/analytics';
inject();
Step 4: Push the changes to your git repository to see the updates.
Great job! You have successfully deployed your MERN application and activated analytics for your project.
Similar Reads
How To Use MERN Stack: A Complete Guide
The MERN stack, comprising MongoDB, ExpressJS, ReactJS, and NodeJS, is a powerful framework for building modern web applications. MongoDB offers a scalable NoSQL database, ExpressJS simplifies server-side development, ReactJS creates dynamic user interfaces, and NodeJS enables server-side JavaScript
8 min read
Deployment Basics in MERN
Deploying a MERN stack application involves hosting both the front end and back end on a live server, making it accessible to users over the internet. MERN stands for MongoDB, ExpressJS, ReactJS, and NodeJS, and each component needs to be properly configured for deployment. The process ensures that
7 min read
MERN Stack Project Deployment - A Step-by-Step Guide
Deploying a MERN Project is an important step in making your app accessible to all. This process involves moving your application from a development environment to a production server where it can handle real traffic. Proper deployment ensures that your website runs smoothly, securely, and efficient
3 min read
Multi Factor authentication using MERN
This article will guide you through creating a Multi-Factor Authentication (MFA) project using the MERN. This project aims to enhance security by implementing a multi-step authentication process. Users will be required to provide multiple forms of identification for access, adding an extra layer of
5 min read
5 Simple Steps for Authentication and Authorization in MERN Stack
Implementing authentication and authorization in a MERN stack application is crucial for ensuring the security of your application and protecting sensitive data. Here's an elaboration on the five simple steps you can take to achieve this: Table of Content Implementing Authentication and Authorizatio
8 min read
Security Basics in MERN
Web development refers to the creating, building, and maintaining of websites. It includes aspects such as web design, web publishing, web programming, and database management. One of the most famous stacks that is used for Web Development is the MERN stack. This stack provides an end-to-end framewo
3 min read
Authentication and Authorization with OAuth
OAuth (Open Authorization) is the open standard for token-based authentication and authorization on the Internet. It can allow third-party services to exchange information without exposing the user credentials. In this article, we will guide you on how to implement the OAuth in the MERN stack applic
6 min read
Express Routing in MERN Stack
Express is a powerful framework for building web applications and APIs in NodeJS. When integrated into the MERN (MongoDB, Express, React, Node.js) stack, Express handles server-side routing and provides a robust foundation for handling HTTP requests and responses. In this article, we will explore ho
3 min read
What to learn after MERN Stack?
Congratulations on mastering the MERN (MongoDB, Express.js, React, Node.js) stack! You've built dynamic and robust web applications, but the world of full-stack development is vast and ever-evolving. Wondering what's next on your learning journey? Let's explore the avenues you can take to broaden yo
4 min read
5 Essential Tools Every MERN Stack Developer Should use
To increase productivity, efficiency, and development experience, it is very important to have the right set of tools. In this post, we will explore the 5 most important essential tools that everyone should use if you are a MERN developer. In full-stack web development, the MERN stack is one of the
3 min read