Search code examples
javascriptviewejspublic

Cannot find route to 'js' within 'Public' folder...using'views'?


I have a structure similar to the following:

--Public
 --js
  --main.js
--Views
 --Pages
  --about.ejs
 --Partials 
  --head.ejs
  --header.ejs
  --footer.ejs
--Server.js

In my HTML (.ejs) page (about.ejs) I have the path to use the 'main.js' within the 'Public' folder defined as

    ...
    <script src="/public/js/main.js"></script>
    ...

However my tests indicate this is failing. I simply attempt to change the 'innerHTML' of a paragraph on the 'about.ejs' page within the 'main.js' as the test...since nothing happens I assume the HTML (.ejs) page is not able to find the javascript file within the 'Public' folder. Any help appreciated greatly...this is immensely frustrating.


Solution

  • I think you use NodeJs. Probably, you need to serve static files.

    Expressjs's serving static files