Load HTML page on localhost

Hello everyone,

I have just tried to build up a server on localhost to display an html page. All good so far. The problem arises when I try to style my html page with a css file.

Consider that all my file are in the same directory.

  1. App.js
const http = require('http');
var express = require('express');
var path = require('path');
var app = express();

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

let {requestListener} = require('./callbackFile.js');
const PORT = process.env.PORT || 4001;

const server = http.createServer(requestListener);
console.log("express server should be up&running. Please go to http://localhost:"+PORT);
  1. Callback file
const fs = require('fs');

module.exports = {
  requestListener: (req, res) => {
  fs.readFile('./ws.html',  'utf-8', (err, data) => {
    if (err){
      res.writeHead(200, {'Content-Type': 'text/html'});
    } else {
    res.writeHead(200, {'Content-Type': 'text/html'});
  1. ws.html
<!DOCTYPE html>


<link rel="stylesheet" type="text/css" href="style.css">
<title> website page </title>

<h1> Web server up & Running </h1>
<h4> Express Server listening on port 4001 </h4>


and finally style.css

h1 {
	color: "red";

If I run node app.js and I go to local host I can see the page but with no css styling…could you please help me?


have you tried setting your static to just __dirname ? I think your reference might be broken because of that extra /

Thanks for you reply! Still not working :confused: