Logo

dev-resources.site

for different kinds of informations.

Deploy react, node projects for free on vercel

Published at
6/17/2024
Categories
webdev
beginners
deployment
Author
ppraneesh
Categories
3 categories in total
webdev
open
beginners
open
deployment
open
Author
9 person written this
ppraneesh
open
Deploy react, node projects for free on vercel

Looking to deploy your projects without spending a dime? You've come to the right place. There are several platforms out there that offer free deployment with some resource limitations. Some of the options include:

  • GitHub Pages
  • Glitch
  • Render
  • Netlify
  • Vercel
  • Digital Ocean

Among these, I find Vercel to be the best for hobby projects. It's free, even for backend applications, and it boasts a 99% uptime. I was pleasantly surprised when my Node and Flask applications worked seamlessly on Vercel. In this blog, I'll show you how to deploy a frontend (React.js), a Node.js backend, and even connect MongoDB to your backend.


Deploying React.js with Vercel

Let's start with deploying a React.js application. I used Vite to create my React apps. If you haven't used it before, don't worry; it's straightforward. Here's a step-by-step guide:

  1. Upload Your Project to GitHub Make sure your project is uploaded to your GitHub account.
  2. Create a Vercel Account Sign up for a Vercel account using your GitHub credentials.
  3. Add a New Project on Vercel
  4. Click on the "Add New" button (top right, white color).
  5. Connect your GitHub account.
  6. Choose the repository you want to deploy.
  7. Type in your project name.
  8. Select the root directory (where your React files are located, e.g., frontend/reactfile/).
  9. Hit deploy.
  10. And that's it! Your project will be deployed, and you'll get a URL ending with vercel.app.

Deploying Node.js with Vercel

Deploying a Node.js application is a bit more involved, but don't worry, I've got you covered. Follow these steps carefully:

  1. Create a directory named 'api' in your project folder.
  2. Place your main server logic in index.js inside the /api directory.
  3. Organize Additional Files
  4. If you have additional server files (e.g., teacherAPI.js), place them in the /api directory.
  5. Ensure Correct File Placement: Make sure package.json, package-lock.json, and .gitignore are outside the /api directory.
  6. Create vercel.json: In your project folder, create a file named vercel.json and paste the following content:
{
"version": 2,
"rewrites": [
    {
    "source": "/(.*)",
    "destination": "/api"
    }  
]
}
Enter fullscreen mode Exit fullscreen mode
  1. Commit your changes and push your project to GitHub.
  2. Deploy on Vercel: Go to Vercel and click "Add New" and select your repository.
  3. Set the framework preset to "Other."
  4. Ensure your root directory contains /api, .gitignore, package.json, etc.
  5. Copy your .env file content and paste it into the environment variables section on Vercel.
  6. Hit Deploy and voila! Your Node.js application is now deployed.

File Structure for Node.js Backend
Here's a visual representation of the file structure:

root directory
    |___
        |_ api
        |     |_ index.js
        |     |_ middlewares
        |_ package.json
        |_ .gitignore
Enter fullscreen mode Exit fullscreen mode

Connecting MongoDB to Your Node Server

If you're using MongoDB with your Node server, you'll need to configure Vercel a bit differently. However, I've encountered issues with MongoDB disconnecting after a while. I recommend using Firebase instead, which is as simple as MongoDB and more stable for this setup.

Final Thoughts

I hope this guide helps you deploy your projects easily and efficiently. Experiment, learn, and happy coding!
Feel free to reach out if you have any questions or need further assistance. Keep experimenting and keep coding!

deployment Article's
30 articles in total
Favicon
clickonce silent install
Favicon
How to Deploy a Node.js App to DigitalOcean Droplet or Other Linux VM
Favicon
Cรณmo Implementar una Aplicaciรณn Node.js en un Droplet de DigitalOcean y otra VM
Favicon
CKA Recap -- Deployment
Favicon
Pipeline CD en Jenkins para terraform AWS EKS segunda parte (plugin AWS Credentials)
Favicon
Planning a Google Workspace Deployment
Favicon
Como Implantar um Aplicativo Node.js em um Droplet do DigitalOcean e outra VM
Favicon
Using Coolify to Simplify Deployments
Favicon
Creating a Custom Role for Secure Bicep Deployments in Azure
Favicon
Understanding Blue-Green Deployment Strategy
Favicon
Running a Project Without Installing Dependencies
Favicon
Deploying Next.js Apps on Vercel: A Step-by-Step Guide for Beginners
Favicon
Implementando Despliegues Blue-Green con AWS Route 53
Favicon
Continuous Delivery vs. Release Management: Finding the Right Balance
Favicon
Unlocking the Power of Ruby on Rails 8: What Developers Need to Know
Favicon
How to Deploy a Web App Using Azure DevOps
Favicon
Implementing Multi-Region Deployment for High Availability in Azure
Favicon
How to Connect a Domain to Cloudflare and a Modern Deployment Platform
Favicon
Helm: Introduction
Favicon
Deploy Django App Shared Hosting
Favicon
redis ACTION REQUIRED: Version approaching end of life
Favicon
How to Build Personal Website for Free With Hugo
Favicon
Automate Deployment in DevOps with DevOps Tools: The Ultimate Guide
Favicon
Deploying a Static Website with Docker: A Comprehensive Guide
Favicon
Automate Your Vue Deployment: A Step-by-Step Guide to Using GitHub Actions
Favicon
Setting up DigitalOcean Spaces for Django Media
Favicon
Managing environment variables in Angular apps
Favicon
The FastAPI Deployment Cookbook: Recipe for deploying FastAPI app with Docker and DigitalOcean"
Favicon
Deploy react, node projects for free on vercel
Favicon
Github as Helm repository

Featured ones: