DEV Community

Cover image for Deploying Your Node.js Backend for Free on Vercel
Joodi
Joodi

Posted on

Deploying Your Node.js Backend for Free on Vercel

Deploying frontends for free? Super easy! Tools like Vercel, Firebase, and GitHub Pages make it a breeze. Heck, you can even host a static site on Google Drive! But when it comes to backend APIs, the free options shrink significantly 🥲. Today, I’ll show you how to deploy your Node.js backend to Vercel without spending a dime!

Image description

Stay tuned until the end, and I’ll throw in a few bonus free hosting options you might not know about! 🤩


1. Start Your Node.js Project

First, let’s spin up a simple Express.js backend. Open your terminal, navigate to your desired folder, and run these commands:

mkdir my-express-backend  
cd my-express-backend  
npm init -y  
npm install express  
Enter fullscreen mode Exit fullscreen mode

Next, create a file at api/index.js and add the following code to set up a basic Express server:

const express = require("express");  
const app = express();  

app.get("/", (req, res) => res.send("Express on Vercel"));  

app.listen(3000, () => console.log("Server ready on port 3000"));  

module.exports = app;  
Enter fullscreen mode Exit fullscreen mode

2. Prepare for Vercel 🚦

Now, you need to add a vercel.json file in the root of your project to tell Vercel how to handle your backend. Add this configuration:

{  
  "version": 2,  
  "rewrites": [{ "source": "/(.*)", "destination": "/api" }]  
}  
Enter fullscreen mode Exit fullscreen mode

3. Test Locally

Before deploying, let’s test it on your machine. First, install the Vercel CLI:

npm install -g vercel  
Enter fullscreen mode Exit fullscreen mode

Log in using vercel login, and then run your project locally:

vercel dev  
Enter fullscreen mode Exit fullscreen mode

Now, visit http://localhost:3000 to see your backend in action! 🎉


4. Deploy to Vercel

Time to go live! You can deploy using three methods:

  1. Vercel CLI
  2. Manual setup on the dashboard
  3. GitHub integration (the easiest and most automated option).

Here’s how to deploy using GitHub:

  • Push your project to a GitHub repo.
  • Log in to Vercel and click “New Project.”
  • Import your repo, set up environment variables (if needed), and click "Deploy."

Boom! 🎉 Your backend is live with a public URL!

Image description
Import the repository that you need to deploy.

Image description

Through here, we can add environmental variables.


Limitations of Free Hosting

While Vercel’s free Hobby account is great, it has limits—like request quotas and sleep mode for inactive projects. If you’re aiming for a production-ready app, you might need to upgrade.


Alternatives to Vercel 😱

Looking for more free hosting options? Check out Render, another excellent platform similar to Vercel. It’s simple and supports backend deployment effortlessly.


And there you go! Your Node.js backend is live on Vercel, and you didn’t spend a penny. Let me know how your deployment goes or if you discover other cool platforms! 😊

Top comments (0)