Skip to content

Instantly share code, notes, and snippets.

@zeel-codder
Last active February 9, 2025 06:46
Show Gist options
  • Save zeel-codder/527a59218489c585f0a90279c7ad6147 to your computer and use it in GitHub Desktop.
Save zeel-codder/527a59218489c585f0a90279c7ad6147 to your computer and use it in GitHub Desktop.
Deploying a Node.js Express App on Vercel

πŸš€ Deploying a Node.js Express App on Vercel

This guide will help you deploy your plain Express.js app on Vercel step by step.

πŸ“Œ Repository: Recursion Hub


πŸ› οΈ 1. Add vercel.json Configuration

Create a vercel.json file in the root of your project and add the following configuration:

{
  "version": 2,
  "rewrites": [{ "source": "/(.*)", "destination": "/server.js" }],
  "builds": [{ "src": "server.js", "use": "@vercel/node" }]
}

πŸ”Ή Explanation:

  • rewrites: Redirects all incoming requests to server.js.
  • builds: Specifies that server.js should be handled using Vercel’s Node.js runtime.

πŸš€ 2. Deploy the App

Run the following commands in your project root:

# Install Vercel CLI globally
npm install -g vercel  

# Start local development server
vercel dev  

# Deploy to Vercel
vercel  

Once the deployment is complete, Vercel will provide a live URL for your app. πŸŽ‰


πŸ”— 3. Connect GitHub for Automatic Deployments

πŸ“Œ Auto-Deploy on GitHub Push

After linking GitHub, your app will automatically redeploy whenever you push changes to the repository.

image

⏸️ 4. Enable Auto-Deploy only for Main Branch

If you want to disable auto-deploy for all branches other than main, follow these steps:

image


πŸŽ‰ Done!

Your Express.js app is now live on Vercel! πŸš€ If you have any issues, check out the [Vercel Docs](https://vercel.com/docs) or let me know. Happy coding! 🎯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment