I have recently started to build my first Node.js app using Express. I have used the latest Express generator to create a skeleton app and I have successfully create several different layouts using Jade and CSS - this all works fine.
However, I cannot seem to get my client side JS to work. In my public folder I have a separate front end JS file and the only thing it contains is an alert (just for testing purposes). I can successfully navigate to the file in the browser and I am not receiving any console errors, however the alert never fires - What am I doing wrong?
I have recently started to build my first Node.js app using Express. I have used the latest Express generator to create a skeleton app and I have successfully create several different layouts using Jade and CSS - this all works fine.
However, I cannot seem to get my client side JS to work. In my public folder I have a separate front end JS file and the only thing it contains is an alert (just for testing purposes). I can successfully navigate to the file in the browser and I am not receiving any console errors, however the alert never fires - What am I doing wrong?
Share Improve this question edited Jul 28, 2016 at 13:55 syscll asked Aug 17, 2015 at 20:02 syscllsyscll 1,0312 gold badges11 silver badges27 bronze badges 4- If you can navigate to the file in the browser, and you're linking to it in the same way in your html, it should be working. We'd need to see both the js, and the html that includes it as well as the express code that serves the static files and the folder structure to further diagnose this. – Kevin B Commented Aug 17, 2015 at 20:05
- Did you import the js in the html file you are serving? CAn you check if your JS file is being loaded? – albertosh Commented Aug 17, 2015 at 20:06
- 2 Well, I feel like an amateur. I was using href to reference my script instead of src. It all works fine now. – syscll Commented Aug 17, 2015 at 20:10
- 2 I would answer my own question and mark it as the answer, good job :) – beautifulcoder Commented Aug 17, 2015 at 20:49
1 Answer
Reset to default 3In order to solve this problem I had to change the link reference to a script reference in my HTML. I also had to ensure I served static files in Express.
http://expressjs./starter/static-files.html