🚀 Deployed an Express App to the Cloud (with Render)

Palash ShrotePalash Shrote
1 min read

Source code - https://github.com/palashshrote/quizzy

Live on - https://quizzy-lase.onrender.com/

Deploying an Express.js app on the cloud isn’t as daunting as it sounds — especially with Render, which offers clear and concise documentation (https://render.com/docs/deploy-node-express-app) to guide.

✅ My Deployment Process

I started by uploading my project to GitHub and followed the steps outlined in Render’s docs. Simple and effective!

⚠️ Error I Encountered

Initially, I hardcoded the port number in my Express app (const port = 3000), which caused the deployment to fail.

💡 How I Fixed It

To make my app cloud-compatible, I:

  1. Created a .env file with:
    PORT=3000

  2. Installed the dotenv package.

  3. In my app:

    • Imported dotenv: import dotenv from "dotenv";

    • Configured it: dotenv.config();

    • Applied: const port = process.env.PORT || 3000;

  4. Overrode the environment variable in the Render dashboard (you can set it under the "Environment" tab).

⚙️ Optimizations

I also ensured a clean GitHub push by using a .gitignore file to exclude:

  • node_modules/

  • .env

  • package-lock.json

🤯 Fun Fact

Even if you don’t use the dotenv package or don’t manually set the port, it still works on Render.

That’s because:

  • Render automatically provides a PORT via environment variables.

  • The default port is typically 10000 (but the app still needs to bind to process.env.PORT).

0
Subscribe to my newsletter

Read articles from Palash Shrote directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Palash Shrote
Palash Shrote