0

when putting up my index.pug page on cloud9, i can access the page correctly using (appname).c9users.io/. however i am using external css and js files, however i get a bunch of 404 errors when i include the css and js files even though they are in the same folder as my index.pug page.

i thought this might be some stupid chmod permissioning error where i hadn't set up the cloud9 environment right but it wasn't. just putting up this question because i wasted a bunhc of time on it as an express newbie.

swyx
  • 2,378
  • 5
  • 24
  • 39
  • discovered this is a link of this http://stackoverflow.com/questions/5924072/express-js-cant-get-my-static-files-why?rq=1 – swyx Dec 26 '16 at 06:37
  • Also relevant: [Loading resources in express](http://stackoverflow.com/questions/34505215/loading-resources-in-express/34506377#34506377) and [css and jss files are not loading](http://stackoverflow.com/questions/39341995/at-node-express-execution-css-and-js-files-are-not-loading/39342125#39342125) – jfriend00 Dec 26 '16 at 16:14

1 Answers1

0

the correct answer is i forgot to set up the routing for other files. ie

app.use('/public', express.static(process.cwd() + '/public'));

for longer form explanation see http://www.clementinejs.com/tutorials/tutorial-beginner.html#AddingAdditionalElementstoIndex.html

hope this helps future me's

swyx
  • 2,378
  • 5
  • 24
  • 39
  • Yes. It sounds like you didn't realize that Express serves NO files by default. There must be a route that covers every file you want the web server to serve. As you discovered, you can use a route with `express.static()` to cover all files in a given directory. – jfriend00 Dec 26 '16 at 06:46
  • i assumed that because i already defined the '/' route to index.pug it would serve all the files in the same folder as my index.pug but it was a poor assumption. just throwing it up on SO to help future dolts like me – swyx Dec 26 '16 at 14:27