I have created a simple static page in nodejs using the default express library.
However, when I run it, nodejs is unable to pick up the public files and throws 404 on them.
I believe that the paths that I have given are correct. This is driving me mad. I knoww the problem has to be so tiny and simple to be face-palm worthy but I am unable to find it.
Can you please help me here.
The code is on github at
Rishavs/ComingSoonPage
Thanks for your time and help.
~ Rishav
The
express.staticmethod does not include subfolders recursively. Your scripts and styles are under public/javascripts and public/stylesheets respectively. You have to let express know those folders contain static files that should be served directly, like so:The last two lines are the important ones. Note that there are two arguments passed to the
app.usemethod. The first one tells what is the path where the script will be served (a.k.a. what you’d have to type in the browser to get it). The second one is the physical location of the file on the server.