Build and Host a Free API with Express + Render
Have you ever wanted to share your own API without paying for servers or complex infrastructure? Thanks to platforms like Render, you can deploy a Node.js API for free in just a few steps! In this post, I’ll show you how to build a simple REST API using Express.js and host it live on Render.
This guide is perfect for beginners and junior developers who want to test their projects, create mock APIs, or practice backend development without worrying about costs.
🚀 Why Use Express and Render?
Express.js is a lightweight and flexible web framework for Node.js, making it easy to build REST APIs. Render offers free hosting for web services, so you can share your API endpoints without paying a dime.
Some benefits of this approach:
- Zero cost for small projects.
- Simple GitHub-based deployment.
- Scalable and beginner-friendly platform.
🛠 Step 1: Create a Basic Express API
Let’s start by creating a new Node.js project with Express:
mkdir free-express-api
cd free-express-api
npm init -y
npm install express
Now create a server.js
file:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({ message: 'Welcome to my free API!' });
});
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
🔒 Step 2: Add a Procfile
Render uses a start
command. Update package.json
:
"scripts": {
"start": "node server.js"
}
🌐 Step 3: Push to GitHub
Create a new GitHub repository and push your code:
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/free-express-api.git
git push -u origin main
⚡ Step 4: Deploy on Render
Follow these steps:
- Sign up at Render.
- Click New Web Service.
- Connect your GitHub repository.
- Choose
Node
as the environment and set the start command tonpm start
. - Deploy your service!
Your API will now have a live URL like https://your-api.onrender.com
.
💡 Real-World Use Cases
- Mock backend for frontend projects.
- Public APIs for learning or sharing data.
- Prototyping ideas before moving to production hosting.
🔗 Related Reads
If you’re exploring backend deployment, you might also like: Deploying a Full Stack App on a VPS (Step-by-Step)
📚 Useful Resources
✅ Wrapping Up
With Express and Render, hosting your own API for free has never been easier. You now have a live API endpoint to test and share. Try adding new routes or connecting it with a frontend app.
What’s next? Try building your own public API and share it with friends or in your portfolio. Have questions? Drop a comment below!
Hi Everyone, please do not spam in comments.