Member-only story

How to deploy a static website on heroku

FS Ndzomga
2 min readMar 31, 2023

To deploy your static website on Heroku, you'll need to create a simple back-end server using a language supported by Heroku, such as Node.js. Here's a step-by-step guide to deploying your project on Heroku:

  1. Install Node.js and npm (if you haven't already): Download and install Node.js from https://nodejs.org/en/download/.
  2. Install the Heroku CLI (if you haven't already): Download and install the Heroku Command Line Interface (CLI) from https://devcenter.heroku.com/articles/heroku-cli.
  3. In your project folder, create a new file called package.json with the following content:
{
"name": "your-project-name",
"version": "1.0.0",
"description": "A simple static website",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
},
"engines": {
"node": "14.x"
}
}

4. Replace "your-project-name" with the actual name of your project.

5. In your project folder, create a new file called server.js with the following content:

const express = require('express');
const path = require('path');
const app = express();

app.use(express.static(path.join(__dirname, './')));

app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, './index.html'));
});

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

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

--

--

FS Ndzomga
FS Ndzomga

Written by FS Ndzomga

Engineer passionate about data science, startups, philosophy and French literature. Built lycee.ai, discute.co and rimbaud.ai . Open for consulting gigs

No responses yet