Skip to content

Developer

🧠 Heroku Deployment

Heroku expects a Node.js app to have a server.js (or similar) and a package.json. Heroku won’t serve plain HTML/CSS/JS without a minimal server process like express.

βœ… Requirements

  • A Heroku account
  • Heroku CLI (installed in Gitpod)
  • Git (already in Gitpod)
  • A static site directory

πŸ“ Project Structure

Assume you have a structure like:

/static-site
β”‚
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ site
β”‚       │── index.html
β”‚   └── style.css
β”‚
β”œβ”€β”€ server.js
β”œβ”€β”€ package.json
β”œβ”€β”€ .gitignore

🧩 Step-by-Step Guide

1. Create a minimal Express server

Create server.js:

const express = require("express");
const path = require("path");

const app = express();
const PORT = process.env.PORT || 3000;

// Serve static files from the 'public' directory
app.use(express.static(path.join(__dirname, "public/site/")));

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

2. Create package.json

If not already created:

npm init -y

Then install express:

npm install express

Update the scripts section in package.json:

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

3. Add a .gitignore file

node_modules

4. Push to Heroku

Heroku will install dependencies, detect it's a Node.js app, and run the server.

🧠 Why This Works

  • Heroku requires a start script in package.json.
  • Heroku serves dynamic apps, so for static files, you need a server (e.g., express) to serve index.html and assets.
  • public/site/ is your static site root.