Home >Web Front-end >JS Tutorial >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!
Stay tuned until the end, and I’ll throw in a few bonus free hosting options you might not know about! ?
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
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;
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" }] }
Before deploying, let’s test it on your machine. First, install the Vercel CLI:
npm install -g vercel
Log in using vercel login, and then run your project locally:
vercel dev
Now, visit http://localhost:3000 to see your backend in action! ?
Time to go live! You can deploy using three methods:
Here’s how to deploy using GitHub:
Boom! ? Your backend is live with a public URL!
Import the repository that you need to deploy.
Through here, we can add environmental variables.
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.
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! ?
The above is the detailed content of Deploying Your Node.js Backend for Free on Vercel. For more information, please follow other related articles on the PHP Chinese website!