Cloud Computing

How to Deploy a Node.js Backend for Free

Deploying a Node.js backend does not always require a paid server. Several hosting platforms offer free plans that allow developers to deploy APIs, test…

D
DevByteTechnical Author
Published
7 min read7 views
How to Deploy a Node.js Backend for Free

Deploying a Node.js backend does not always require a paid server. Several hosting platforms offer free plans that allow developers to deploy APIs, test applications, and launch small projects without paying for infrastructure upfront.

Whether you are building a REST API, an authentication service, or a backend for a React or mobile application, choosing the right free hosting platform can help you get started quickly.

In this guide, we will explain how to deploy a Node.js backend for free, compare popular hosting platforms, and walk through the deployment process step by step.

1. Choose a Free Node.js Hosting Platform

Before deploying your application, choose a hosting platform that supports Node.js and fits your project's requirements.

Popular options include:

Render: Offers a straightforward deployment process for Node.js web services, with a free tier subject to usage limits.

Vercel: Suitable for API routes and serverless functions, particularly when your backend fits its execution model.

Netlify: Supports serverless functions for API endpoints and backend functionality.

Google Cloud Run: Can run containerized Node.js applications, with usage-based pricing and eligible free-tier allowances.

Fly.io: Supports deploying Node.js applications, but do not assume that a free production allowance is available.

Free-plan availability, resource limits, sleeping behavior, and usage charges can change. Check the platform's current pricing and terms before deploying.

For a beginner deploying a conventional Express.js backend, Render is a straightforward option to start with.

2. Prepare Your Node.js Backend

Before deploying, make sure your backend runs correctly on your local machine.

A basic Express.js project might have this structure:

node-backend/
├── server.js
├── package.json
└── .gitignore

If you do not already have a project, create a new folder and initialize it:

mkdir node-backend
cd node-backend
npm init -y
npm install express

Create a file named server.js:

const express = require("express");

const app = express();

app.use(express.json());

app.get("/", (req, res) => {
  res.json({
    message: "Node.js backend is running!",
  });
});

app.get("/api/health", (req, res) => {
  res.json({
    status: "ok",
  });
});

const PORT = process.env.PORT || 3000;

app.listen(PORT, "0.0.0.0", () => {
  console.log(`Server running on port ${PORT}`);
});

This example creates two endpoints: / and /api/health.

The application uses process.env.PORT because hosting platforms typically assign the port dynamically. Binding to 0.0.0.0 allows the application to accept connections from outside its local environment.

3. Configure the Package Scripts

Open package.json and make sure the application includes a start script.

For example:

{
  "scripts": {
    "start": "node server.js"
  }
}

Keep your existing project metadata and dependencies when updating the scripts.

Test the backend locally:

npm start

Open the following URLs in your browser:

http://localhost:3000/
http://localhost:3000/api/health

If the API returns JSON successfully, your basic backend is ready for deployment.

4. Upload Your Code to GitHub

Many hosting platforms can deploy applications directly from a GitHub repository.

First, create a .gitignore file:

node_modules/
.env

Do not upload .env files containing database passwords, API keys, or other secrets.

Initialize Git and push your project to a new GitHub repository:

git init
git add .
git commit -m "Prepare Node.js backend for deployment"
git branch -M main
git remote add origin YOUR_GITHUB_REPOSITORY_URL
git push -u origin main

Replace YOUR_GITHUB_REPOSITORY_URL with your actual repository URL.

Your code is now available for the hosting platform to access.

5. Deploy Your Node.js Backend on Render

Render provides a beginner-friendly way to deploy a Node.js web service from a GitHub repository.

<AsyncImageGroup query={["Render cloud hosting dashboard create new web service GitHub repository","Render web service settings Node.js build command start command dashboard"]} aspectRatio="5:4" layout="bento" />

Follow these steps:

  1. Visit the <Link url="https://render.com/" title="Render website"/> and create an account.

  2. Connect your GitHub account.

  3. Create a new Web Service.

  4. Select the repository containing your Node.js backend.

  5. Enter the required deployment settings.

Use settings similar to these:

Setting

Value

Runtime

Node

Build Command

npm install

Start Command

npm start

Branch

main

  1. Choose the available free instance option if your project is eligible.

  2. Click the deployment button and wait for the build to complete.

  3. Open the service URL provided by Render.

Your backend should now be available through a public URL, typically using HTTPS.

Important: Free services may have limited CPU, memory, usage, or availability. Some free web services sleep after inactivity and may take time to respond to the first request. Check the current plan details before using a free service for a production application.

6. Configure Environment Variables

Real-world Node.js applications often require environment variables for database connections, authentication, and third-party APIs.

For example:

const databaseUrl = process.env.DATABASE_URL;
const jwtSecret = process.env.JWT_SECRET;

Add the corresponding values through your hosting platform's environment variable settings.

Common environment variables include:

  • DATABASE_URL

  • JWT_SECRET

  • API_KEY

  • NODE_ENV

Never hardcode production secrets in your source code or commit them to GitHub.

If your application uses a database, ensure the database is hosted separately or provided by a suitable managed service. A free backend host does not necessarily include a free database.

7. Connect a Database to Your Backend

If your application needs to store user accounts, products, orders, or other information, configure a database connection.

Popular database options include PostgreSQL, MongoDB, and MySQL. The available free plans depend on the database provider and may have storage, connection, or usage limits.

For example, a backend using PostgreSQL can read its connection string from an environment variable:

const { Pool } = require("pg");

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: process.env.NODE_ENV === "production"
    ? { rejectUnauthorized: false }
    : false,
});

Install the PostgreSQL client if needed:

npm install pg

This is an illustrative connection example. Configure TLS according to your database provider's instructions; production deployments should validate certificates rather than disabling verification.

Test database connectivity, query permissions, and connection limits before connecting your frontend.

8. Test Your Deployed API

After deployment, test your backend using its public URL.

For example:

https://your-service.onrender.com/
https://your-service.onrender.com/api/health

You can also use Postman or curl to test endpoints:

curl https://your-service.onrender.com/api/health

Check the following before considering deployment complete:

  • The homepage or health endpoint responds correctly.

  • API routes return the expected data.

  • Database queries work.

  • Authentication and authorization behave correctly.

  • CORS allows only the required frontend origins.

  • Secrets are configured securely.

  • Deployment logs do not show errors.

Replace the sample domain with the URL provided by your hosting platform.

9. Deploy Updates Automatically

When your hosting platform is connected to GitHub, you can often enable automatic deployments whenever you push changes to your selected branch.

For example:

git add .
git commit -m "Update API endpoint"
git push origin main

The platform can detect the new commit, build the application, and deploy the updated backend.

For production projects, consider using a separate staging environment, automated tests, and a rollback plan before deploying changes to users.

10. Common Problems When Deploying for Free

Application fails to start: Check the start command, package.json, build logs, and application entry point.

Port binding errors: Use the hosting platform's assigned PORT environment variable.

API works locally but not online: Check environment variables, database connectivity, allowed origins, and platform logs.

Database connection fails: Verify the connection string, network access, TLS configuration, and database limits.

First request is slow: The free plan may suspend inactive services or have limited resources.

Deployment fails after a Git push: Review dependency installation, Node.js version compatibility, build output, and runtime logs.

Free usage limits are exceeded: Check your provider's current resource allowances and upgrade or choose another suitable deployment option if necessary.

Conclusion

Deploying a Node.js backend for free is a practical way to launch a prototype, learn deployment workflows, and test APIs without paying for a dedicated server. By preparing your Express application, pushing it to GitHub, configuring environment variables, and deploying it to a platform such as Render, you can make your backend accessible online.

However, free hosting comes with limitations involving resources, uptime, sleeping behavior, and database availability. Before using it for a business-critical application, evaluate your performance, security, and reliability requirements.

Need help deploying your backend? Dotcube Technologies helps businesses build, deploy, and maintain Node.js backends, APIs, and scalable web applications tailored to their project requirements.

D
DevByteAuthor

Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.

Keep Exploring

Related Engineering Dispatches

More guides and architectural patterns you might find valuable.

Browse All Articles↘