'How to link html/css/js web application to nodejs locally?

new to creating web applications, so please go easy on me.

I have a web application coded using html/css/js in a folder right now. On the other hand, I have a simple node.js file called server.js that is connected to my locally hosted mySQL database to perform some simple queries using Express.

I tried to connect the html/css/js files to the node.js file like how you would include a javascript file (using src = ...), but apparently it doesn't work since the browser does not support functions such as "require()" from nodejs.

Could anyone point me in the right direction for me to connect them so that my web application can perform some simple query using the nodejs file? All these are just for my local machine since I'm not going to host the web application



Solution 1:[1]

As you didn't provide any code I'm not sure what you want to do.

Assuming you want to use functionality from the node.js server:
You can't just require the node.js server. You need to run the server seperately by opening a command prompt and typing node server.js in the directory of your server files.
If you want to make queries you probably want to implement an API on your server and use the fetch() function in your browser to query data from the server.

For further help, please provide a screenshot of the folder with the files and upload all files using https://pastebin.com/.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Green_Lab