I am not looking for a piece of code to copy- I am stuck. I used the MySQL driver in node to connect to the SQL database and inserted data into the table. It works fine, but I want to show the data from that table into HTML. I would use client-side js to do something like someDiv.textContent = results but client side doesn't allow me to connect to the database. I could create an endpoint for /showPosts and have it connect to the database but I don't know how I'm going to pass the results I get to the frontend. Any help would be appreciated. Thanks :)
-
This is pretty broad to be meaningfully answered here. But in general you'd either (1) fetch the data when requesting the page and use whatever server-side template engine you're using to add the data to the page, or (2) return a page with no data and make an AJAX request from client-side code to another server-side endpoint to fetch the data and add it to the table client-side.David– David2022-04-26 18:53:51 +00:00Commented Apr 26, 2022 at 18:53
Add a comment
|
2 Answers
I solved the issue a couple of months ago. I used Node on the backend to connect to the database, and created endpoints for the data to be fetched. In the frontend, I did a fetch API call to that exposed endpoint. I also used ejs - that allowed me to create views within my Node application.