Help: multiple js files on client side

Help: multiple js files on client side
0

#1

Hi,

I am two projects away from completing the back end certificate, but I just now realized I don’t know how to incorporate multiple files on client side.

Usually my client page is composed of (at least) two files:

index.html
client.js

I usually pass the client.js file to the client page using the following line in the index.html file:

<script src="/client.js"></script>

Now, say that I have another file utilities.js that I want to pass to the client and this file contains the following function

function foo(){

  console.log("hello World!");

}

How can I call foo from client.js? I am using glitch, but a broader applicable answer on how to structure your app would be appreciated.

Thank you!
Michele


#2

Just make sure both JS files are loaded in your HTML file:


#3

So easy!

Thank you!

I googled it but I never managed to stumble upon that particular stackoverflaw page.


#4

Since you mentioned you’re in the backend section, here is an article on the module.export feature you use in Node to make your server files importable too.

This allows you to break things like your routes or database queries / controllers into their own modules.


#5

Thank you for the tip, I will read in to it!

However, I am already extensively using module.exports and the fact that it doesn’t work on client side got me stuck with the OP problem