manbearpig1 manbearpig1 - 8 months ago 38
Node.js Question

Serve javascript file from public folder with express js

I have a partial for hooking up scripts. It links scripts like the following:

<script src=""></script>

There is only one javascript script that I made myself in that partial. I am unable to serve it. This is what I'm attempting:

<script type="text/javascript" src="/javascripts/myjavascript.js>"></script>

where myjavascript.js belongs to javascripts which belongs to public. The error here is 404 not found.

Please note that scripts from an online source work fine and are being served in the same partial. I can assure you that my spelling is correct and that the file exists at that src location. What am I doing wrong?

My error message attaches a strange extension too. Not sure if that's a clue or not.

enter image description here


You have a typo in your code:

<script type="text/javascript" src="/javascripts/myjavascript.js>"></script>
                                this '>' does not belong here --^

The corrected code would be

<script type="text/javascript" src="/javascripts/myjavascript.js"></script>