I recently created a basic server using Node.js with Express, and configured the public
folder to serve static files.
Within my main index.js
file, I included the following code:
const express = require('express');
const app = express();
const http = require('http').Server(app);
const fs = require('fs');
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
http.listen(3000, () => console.log('server started on *:3000'));
The directory structure is as follows:
root
|---index.js
|---package.json
|---public
| |---index.html
| |---cs
| | |---index.css
| |---js
| | |---index.js
Inside the index.html
in the public
folder, I added this code snippet:
<head>
<script src="js/index.js"></script>
<link rel="stylesheet" src="css/index.css" type="text/css" >
</head>
Despite this setup, the CSS is not rendering properly. Any suggestions on how to fix this issue?