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?

No_Name
  • 155
  • 2
  • 14

1 Answers1

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')
spadletskys
  • 125
  • 7
  • 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 – No_Name Nov 26 '20 at 04:24
  • where is your error? Maybe I can help. Or you can create another post and give me the link. :) – spadletskys Nov 26 '20 at 04:59
  • 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. – No_Name Nov 26 '20 at 17:02