0

I've been unable to get css and js to load on my server. MY file structure is as follows: GAME_Folder enter image description here

HTML

doctype html head link(href='https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap' rel='stylesheet') script(src='https://code.jquery.com/jquery-latest.min.js' type='text/javascript') script(src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js') <script type="text/javascript" src="index.js"></script> link(rel='stylesheet' type='text/css' href='../css/style.css') script(src='/socket.io/socket.io.js') 

Server (serv.js)

enter image description here

I've tried almost everything from the previous stack overflow posts: Failed to load resource: the server responded with a status of 404 (Not Found) Failed to load resource: the server responded with a status of 404 (Not Found) css

Any other suggestions?

1 Answer 1

1

Your routing is wrong...

It should be like this:

app.use(express.static(__dirname + '/public/style.css'); app.use(express.static(__dirname + '/public/index.js'); 

And in your HTML file:

doctype html head link(href='https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap' rel='stylesheet') script(src='https://code.jquery.com/jquery-latest.min.js' type='text/javascript') script(src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js') <script type="text/javascript" src="index.js"></script> link(rel='stylesheet' type='text/css' href='/css/style.css') script(src='/socket.io/socket.io.js') 
Sign up to request clarification or add additional context in comments.

3 Comments

I fixed the error by : app.use(express.static(path.join(__dirname, 'public'))); So I did not need to change the routing. I have a new error now on my socket.io : jQuery.Deferred exception: io is not defined ReferenceError: io is not defined
where is your error? Maybe I can help. Or you can create another post and give me the link. :)
The error was likely due to the fact I had 2 servers, which in my line of thinking, made me assume might work. So what happened was I had to let go of one of my servers as I was unable to merge them. Thanks anyways, your answer was helpful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.