Why is css not getting accepted in node js?

Viewed 30
const fs  = require('fs');
const http = require('http');
const fileContentLoder = fs.readFileSync("index.html");
const fileContentLoderAbout = fs.readFileSync("about.html");
const fileContentLoderError = fs.readFileSync("error.html");

const server = http.createServer((req, res) => {
  console.log(req.url)
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/html');
  if(req.url == "/about"){
    res.end(fileContentLoderAbout);
  }
  else if(req.url == "/"){
    res.end(fileContentLoder);
  }
  else{
    res.end(fileContentLoderError);
    console.log(`Error finding ${req.url}`);
  }
  
});

server.listen(8080,'127.0.0.1',()=>{

  console.log("Server on 127.0.0.1:8080");

});

this is my code and I have been trying get external ccs working and there are no tutorials to help me out with my code how can I get this to work ?

1 Answers

Usually you use JS on frontend to control css like that. maybe you could send responses from node js to which js could change css in the frontend.

Related