Dev Oskii
Dev Oskii

Reputation: 929

What is the correct src= attribute to load scripts from node.js server

Both my p5.js and sketch.js scripts will not load.

My index.html is loaded by Node.js

I think I am misusing the src value in my<script> tag in the HTML. My p5.js script is up one level and in a folder called P5, and my sketch.js file is in a folder called P5Scripts in the same directory as this index.html file.

In the chrome console, I get this message : Loading failed for the <script> with source “http://45.76.140.199:3000/P5/p5.js”.

and

Loading failed for the <script> with source “http://45.76.140.199:3000/P5Scripts/sketch.js”.

I can see that my src attribute is wrong, but what would be the correct way to load these scripts?

index.html:

<!doctype html>
<html>
    <head>
        <title>My Website</title>
    </head>

    <script src="../P5/p5.js"></script>
    <script src="P5Scripts/sketch.js"></script>

    <body>
    </body>
</html>

Upvotes: 1

Views: 753

Answers (1)

Ruben Marrero
Ruben Marrero

Reputation: 1392

There isn't a way to bind nodejs with the DOM elements of your html because nodejs is backend and html DOM elements are frontend.

Since you are trying to modify the html, chances are that what you really want is to use plain javascript which would run on the browser.

Nodejs is a backend technology which runs on the server. At the time the html is displayed nodejs has already done its work and isn't aware of what is going on the page unless AJAX involved.

Have a brief look to client/server model here.

Upvotes: 1

Related Questions