I Deployed the Node.js Server On Vercel for Free π
Use Vercel for RESTFul API for free
Not a member? Read here for free
Vercel is well-known for hosting static websites, but do you know, you can also deploy your Node.js server on it for free?
After Heroku discontinued its free service, I tried to find an alternative that provides free Node.js server hosting. Then I found Vercel, which I was using for my Next.js and React.js projects.
In this article, I will share how you can host your node js server on vercel for free-
Deploying a Node.js Server on Vercel
Follow these steps to deploy your server on vercel-
1. Create a Node.js Server Locally-
If you do not have your project started yet, then create a new Node.js server with Express.js-
- Create a folder for your project-
mkdir my-vercel-node-server
cd my-vercel-node-server- Initialize a Node.js project-
npm init -y- Install Express-
npm install express- Create a file index.js-
// index.js
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Hello from Vercel Node.js Server!');
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});2. Create Vercel.json
{
"version": 2,
"builds": [
{
"src": "./index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}3. Push the Code to GitHub-
Create a GitHub repository and push your code-
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git push -u origin master3. Deploying to Vercel
- Sign Up/Login: Go to Vercel and create an account if you havenβt yet.
- Import Project: Click βNew Projectβ and import your GitHub repository.
- Configure Build and Output Settings:
- Framework Preset: Choose βOtherβ.
- Build Command: Leave it empty unless you have a build process.
- Output Directory: Leave it empty for default settings.
- Environment Variables: Add any necessary environment variables like API keys.
4. Deploy and Test the Server
- Click βDeployβ. The deployment will take a few seconds.
- Once deployed, Vercel will provide you with a URL (e.g., https://your-project.vercel.app).
- Test your server by visiting the URL.
Conclusion
Vercel provides a quick, free and scalable hosting solution for backend projects. It simplifies the deployment process with GitHub integration. Vercel also provides a free subdomain and SSL for your API.
I have been using this for long and found it very useful. What about you, let me know in the comments.
Sample Project: https://github.com/gyanendraknojiya/vercel-node-server
Vercel URL: https://vercel-node-server-zeta.vercel.app
