Attempting to utilize node.js and express for crafting a chat client has proven to be a bit challenging. Whenever I attempt to incorporate external CSS or JS files, I encounter GET errors.
My current configuration in index.js is as follows:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
Within my index.html file, I employ:
<script src="/dropdown.js"></script>
<link rel="stylesheet" type="text/css" href="/style1.css">
for linking the files within the HTML document.
My directory structure looks like this:
index.js
index.html
public
style1.css
dropdown.js
Despite consulting various solutions provided on stackoverflow, none seems to resolve the GET errors. I've experimented with different combinations of express.static/app.static, as well as linking CSS/JS files in the HTML file, but to no avail.