How To Serve Js File That Needs To Be Executed On Client Side?
How do i make my script file available for html file in node js? My server.js file looks like this So how do I make script in file app.js executed?
Solution 1:
You need to put the javascript file in the /public or in a subdirectory of /public. Then reference that file from your index.html.
Right now index.html is looking in __dirname for the javascript file, but in your code you exposed __dirname + '/public'.
Solution 2:
You've set your public available folder to public
, so your .js
, .css
, ... files should be in this folder. A typical structure for the public folder would be something like this:
If you have a directory structure like in above picture, you would reference your JavaScript file like this:
<scriptsrc = "/javascripts/app.js"></script>
Post a Comment for "How To Serve Js File That Needs To Be Executed On Client Side?"