Hi everyone, I've been struggling with an issue for the past couple of days where I can't seem to load my CSS for my Express app.
If anyone has a solution, I would greatly appreciate the help. Below is my server.js code:
const express = require('express');
const app = express();
const { Server } = require('socket.io');
const http = require('http');
const server = http.createServer(app);
const io = new Server(server);
const port = 80;
const path = require('path');
app.get('/', (req, res) => {
app.use(express.static(path.join(__dirname,'css')));
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
socket.on('new-user', name => {
socket.broadcast.emit('user-connected',name);
})
socket.on('send name', (username) => {
io.emit('send name', (username));
console.log(username)
});
// more socket event handlers here...
});
server.listen(port, () => {
console.log(`Server is listening at the https://localhost/`);
});
I have tried using this line of code:
app.use(express.static(path.join(__dirname,'css')));
However, the issue still persists. Can anyone point out if I am doing something wrong here?