How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL)

In this article, I will guide you step by step on how to deploy a full-stack application using Vercel.

You can check the actual deployed project at the bottom of this article under the reference section.

Prerequisites

Before you start depl…


This content originally appeared on DEV Community and was authored by Satomi Nagano / Akikaze1119

In this article, I will guide you step by step on how to deploy a full-stack application using Vercel.

You can check the actual deployed project at the bottom of this article under the reference section.

Prerequisites

Before you start deploying, please ensure that you meet the following requirements:

  • You have a repository on GitHub, with separate frontend and backend folders
  • The connection between the frontend, backend, and the database is confirmed in the testing environment

Deploying the Backend to Vercel

Let's start by deploying the backend.

Step 1. Log in to Vercel

First, log in to Vercel or sign up if you haven't already.
vercel dashboard

Step 2. Add a New Project

Click the "Add New..." button in the red box and select "Project" from the dropdown.

Import an existing project from GitHub. If the target repository is displayed, select the "Import" button in the red box.

🚨If the target repository is not found, you may need to adjust the GitHub access settings. You can change the settings via the "Adjust GitHub App Permissions" link in the green box.
vercel import

How to Adjust GitHub Repository Access Settings

Click the "Adjust GitHub App Permissions" link, select where to import from.
install vercel

On the GitHub settings page, select the target repository from the "Repository access" dropdown and click Save. It should now appear in the Import list on Vercel.
repository access

Step 3. Configure the Project

Once the import is complete, configure the project.
Confiture project

Project Name:
It’s a good idea to add "backend" or "server" at the end of the project name.
(Example: "my-project-backend", "my-project-server", etc.)

A domain will be created using the name you set here plus ".vercel.app".
(Example: my-project-api.vercel.app, my-project-server.vercel.app, etc.)

Framework Preset:
Select "Others" from the dropdown.

Root Directory:
Click the "Edit" button and select the backend directory.
root directory

Build and Output Settings:
No settings are required here, but you can add any if needed.

Environment Variables:
Add the necessary environment variables here. (Note: PORT is not required.)
Environment Variables

Deploy:
Once these settings are complete, click the "Deploy" button.

Step 4. Configure vercel.json

After deployment, add a vercel.json file to the root of the backend folder with the following content:

{
    "builds": [
        {
            "src": "*.js",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "/"
        }
    ]
}

ℹ️ For TypeScript, specify it to read the compiled JS files. (In the example below, the TypeScript output directory ("outDir") is set to ./dist.)

{
  "builds": [
    {
      "src": "dist/server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/server.js"
    }
  ]
}

Step 5. Confirm Server Access

Check if you can access the deployed server. You can verify this from the "Domains" URL.
domain link

If the content of the file is displayed or if you see "Cannot GET /" on the page like this, it was successful! πŸŽ‰πŸŽ‰πŸŽ‰

🚨 If you get a 404 error, there might be an issue with the vercel.json settings, so make sure the specified paths are correct.
404error

Deploying the Frontend to Vercel

Proceed with the frontend deployment in the same way as the backend.

Step 1: On the Vercel dashboard, click the "Add New..." button and select "Project."

Step 2: Import the target project.

Step 3: In the project settings, configure the following:

  1. Project Name: Set a name like "my-project".
  2. Framework Preset: Select "Vite" (or "Create React App" if using React only).
  3. Root Directory: Select the frontend directory, such as client.
  4. Environment Variables: Add any necessary variables.
  5. Deploy: Click the "Deploy" button.

Step 4: Verify by accessing the deployed page. If the site is displayed correctly and the connection to the backend is confirmed, you're done! πŸŽ‰πŸŽ‰πŸŽ‰

Conclusion

That’s it for deploying a full-stack application using Vercel. If things don’t work as expected, double-check your settings and environment variables.

supplement

Reference Video


This video uses MongoDB, so if you're working on a MERN stack project, it might be more relevant.

ℹ️ Note: The video mentions "version": 2 in the vercel.json settings, but the Vercel documentation advises against using the "version" property.

Deployed Project

The project introduced in this article has been deployed and verified using the following tech stack:

Frontend: Vite + React + TypeScript
Backend: Express (Node.js) + TypeScript
Database: Neon (PostgreSQL)
Note: You can use other databases like MongoDB as well.

Repository Structure Example:

β”œβ”€β”€ server             # Backend folder
β”‚   β”œβ”€β”€ dist           # TypeScript output
β”‚   β”œβ”€β”€ controllers
β”‚   β”œβ”€β”€ models
β”‚   β”œβ”€β”€ routers
β”‚   β”œβ”€β”€ services
β”‚   └── server.ts
β”œβ”€β”€ client             # Frontend folder
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ components
β”‚   β”‚   β”œβ”€β”€ utils
β”‚   β”‚   β”œβ”€β”€ App.tsx
β”‚   β”‚   β”œβ”€β”€ index.tsx 
β”‚   β”‚   β”œβ”€β”€ styles
β”‚   β”‚   └── ...
└── package.json

You can check out the actual project here:
Chatbot App
GitHub.


This content originally appeared on DEV Community and was authored by Satomi Nagano / Akikaze1119


Print Share Comment Cite Upload Translate Updates
APA

Satomi Nagano / Akikaze1119 | Sciencx (2024-09-04T22:03:59+00:00) How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL). Retrieved from https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/

MLA
" » How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL)." Satomi Nagano / Akikaze1119 | Sciencx - Wednesday September 4, 2024, https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/
HARVARD
Satomi Nagano / Akikaze1119 | Sciencx Wednesday September 4, 2024 » How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL)., viewed ,<https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/>
VANCOUVER
Satomi Nagano / Akikaze1119 | Sciencx - » How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/
CHICAGO
" » How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL)." Satomi Nagano / Akikaze1119 | Sciencx - Accessed . https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/
IEEE
" » How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL)." Satomi Nagano / Akikaze1119 | Sciencx [Online]. Available: https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/. [Accessed: ]
rf:citation
» How to Deploy a Full-Stack Application on Vercel (ReactJS | Vite | NodeJS | TypeScript | Neon | PostgreSQL) | Satomi Nagano / Akikaze1119 | Sciencx | https://www.scien.cx/2024/09/04/how-to-deploy-a-full-stack-application-on-vercel-reactjs-vite-nodejs-typescript-neon-postgresql/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.