Static Assets not served, Please Help

I’m trying to build an express server on my machine, where I can serve an HTML file as a static file from the public folder, I wrote this code.

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

const app = express();
const port = 3000;
const puplicDirectoryPath = path.join(__dirname, '../puplic');


app.get('/', (req, res) => {
    res.send("<h1>Hello Express!</h1>");

app.listen(port, () => console.log(`app is listening on port ${port}!`));

and this is my folder tree.


When I view it on the browser it shows me the message that is served here but not the content of the HTML file.

app.get('/', (req, res) => {
    res.send("<h1>Hello Express!</h1>");

The contents of the HTML file

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web Server</title>
    <h1>From a static file</h1>

Any Help Please!! … Idk what to do.

Well for one you need to check the path.join, you have a folder named public not puplic.

1 Like

Thank you, I was trying every single solution on the internet and never noticed this typo at all. :sweat_smile: :joy:
thank you again