6

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?

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. 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? 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. Commented Aug 17, 2015 at 20:10
  • 2
    I would answer my own question and mark it as the answer, good job :) Commented Aug 17, 2015 at 20:49

1 Answer 1

3

In 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.com/starter/static-files.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.