Sitemap

I Deployed the Node.js Server On Vercel for Free πŸš€

Use Vercel for RESTFul API for free

--

Not a member? Read here for free

Press enter or click to view image in full size

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
Press enter or click to view image in full size
  • 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}`);
});
Press enter or click to view image in full size

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 master
Press enter or click to view image in full size

3. Deploying to Vercel

Press enter or click to view image in full size
  1. Sign Up/Login: Go to Vercel and create an account if you haven’t yet.
  2. Import Project: Click β€œNew Project” and import your GitHub repository.
  3. 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.
Press enter or click to view image in full size

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

Thank you for reading this article, consider clapping πŸ‘ for this article. Follow me on LinkedIn and GitHub.

--

--

Gyanendra Knojiya πŸ§‘β€πŸ’»
Gyanendra Knojiya πŸ§‘β€πŸ’»

Written by Gyanendra Knojiya πŸ§‘β€πŸ’»

I am a Full Stack developer & Technical writer. To know more, visit www.gyanendra.tech