new web developer here,
I am creating a test website where I can input data and add it to my MongoDB database. I have a JavaScript file that manages the connection with my MongoDB database (app.js), and I have another JavaScript file that manages the elements within my webpage. (script.js)
I am trying to make it so when I load the page where I input data, I can call the method which connects the database, and I can use that allows me to push form data to my MongoDB database.
The only thing I am struggling with is how I would detect that the webpage is loaded and run the method that opens my database.
I am also struggling to understand how to pass my 'db' variable into my script.js file to allow me to get data from my webpage.
Any help is appreciated, I am using WebStorm to create my website.
EDIT: And links to resources that solve a similar issue to mine (basically sending data to MongoDB from a webpage), would be very helpful! I think I am also using nodejs for my app.js file