Render is a popular platform for hosting full stack applications. But like any deployment platform, things can go wrong. This guide provides practical steps for diagnosing and fixing deployment issues when using Render to host your backend.
Symptoms: Build fails or app crashes immediately.
Fix:
Build Command: npm install
Start Command: node server.js
If using ES modules:
Start Command: node --no-warnings server.js
If using TypeScript:
Build Command: npm run build
Start Command: node dist/server.js
Symptoms: Cannot find server.js or crashes on startup.
Fix: Ensure server.js exists and is correctly referenced.
Symptoms: App crashes due to missing config.
Fix: In the Render dashboard, set environment variables like:
PORT=10000
DATABASE_URL=your_connection_string
JWT_SECRET=supersecure
Symptoms: Frontend fetch request fails with a CORS error.
Fix: In Express backend, add:
import cors from "cors";
app.use(cors());
Symptoms: Cannot find modules or start command fails.
Fix: Ensure your dependencies are in dependencies, not just devDependencies in package.json.
Fix: Use the Logs tab in your Render dashboard. Watch out for errors like:
SyntaxError: Cannot use import statement outside a module
Fix by adding "type": "module" in your package.json.
Symptoms: App crashes or fails health check.
Fix: Always use the port provided by Render:
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Symptoms: App restarts or fails health check.
Fix: Add a route to confirm server is up:
app.get("/", (req, res) => res.send("App is running"));
Run your backend locally before deploying:
npm install
node server.js
If using a .env file, load it with dotenv:
import dotenv from "dotenv";
dotenv.config();
process.env.PORT