Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
Why is my HTML file creating a CSS file instead of linking to it?

I'm starting out using Node.js and this is what I have so far...

server.js

var http = require('http');
const PORT = 3000; 

var fs = require('fs'),
    path = require('path'),    
    filePath = path.join(__dirname, 'index.html');

fs.readFile(filePath, {encoding: 'utf-8'}, function(err, html) {
    if (err) throw err;    

    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    }).listen(PORT);

    console.log("Server successfully hosted at http://127.0.0.1:" + PORT + "/");
});

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="styles.css">
  <title>My First Node.js!</title>
</head>
<body>
  <h1>Hello there!</h1>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem perferendis ratione itaque, alias nesciunt nemo porro deserunt animi iusto dolor?</p>
</body>
</html>

styles.css

*, *::before, *::after {
  box-sizing: border-box;
}

h1 {
  text-align: center;
}

p {
  text-align: center;
}

However, when I run the server, none of my CSS styles are showing up. When I used google Dev tools to check, my CSS file had the HTML code in it?

Dev Tools Sources Screenshot

My guess is that the HTML <link rel="stylesheet" type="text/css" href="styles.css"> is somehow creating a CSS file instead of finding the file?

Please let me know if there's any way to fix this.

Thanks.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!