1

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>

1 Answer 1

1

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.

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

2 Comments

I basically want Node.js to eventually trigger events in P5, but for now I just want to load p5 onto the screen :)
From the html you are going to use just plain javascript. Then you will handle your trigger events with ajax from the frontend and send the needed information to the backend. Then and only then is nodejs' time.

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.