Trung Tran
Trung Tran

Reputation: 13771

Javascript file not loading in express / node.js

I have a problem where my javascript file is not loading. Here is my file directory:

app/views/methods.js app/views/methods.handlebars

I want to load the methods.js file in the methods.handlebars page:

<script type="text/javascript" src="./views/methods.js"></script>
<div class="container">
  <div class="form-group">
    <label>First Number:</label>
    <input type="text" name="firstNum">
  </div>
  <div class="form-group">
    <label>Second Number:</label>
    <input type="text" name="secondNum">
  </div>
  <button type="" name="calculate" class="btn btn-default">Calculate</button>
</div>

However, I keep getting a cannot GET error in the console... can someone help?

Thanks!

Upvotes: 1

Views: 92

Answers (2)

Trung Tran
Trung Tran

Reputation: 13771

I'm a total noob at this - i forgot that I need to reset the node server whenever i make server-side code changes. What I have totally works.

Upvotes: 0

Paul S Chapman
Paul S Chapman

Reputation: 832

I think your problem might be related to it being in the Views directory.

Try creating a directory for scripts in the public directory.

So assuming you create a javascript directory that would make your call to get the script as

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

Upvotes: 2

Related Questions