I have an express app with an index.js that has the following:
<form method="post" action="searchAll">
<input type="text" name="keyword"/>
<button type="submit">Submit</button>
</form>
This functions well as a form that takes a keyword and searches my database and then follows up with a POST of the results.
But can I have a button like this:
<button id="refreshDB">REFRESH DATABASE</button></br>
which doesn't send any data to the server other than calling a server side function? The function (located in app.js or db.js on the server) takes no parameters and doesn't follow up with a post request. I'm thinking something like the following:
<button id="refreshDB">REFRESH DATABASE</button>
<script>
var button = document.getElementById('refreshDB');
button.addEventListener('click', function() {
// SOMEHOW TELL SERVER TO RUN FUNCTION
// similar to the html <form method="post" action="refreshDB">?
});
</script>
I know I'm missing something really basic. I have a basic understanding of routing, but have no idea how to use one for a simple one-way function call. All of the help I find usually uses a form to submit data. The ExpressJS documentation is helpful, but I can only find server side code when it comes to routes like this.
This popular question is asking something similar, but the answer uses a form.
Can help identify what basic 'thing' I am missing? Thank you!