0

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 :)

1
  • 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. Commented Apr 26, 2022 at 18:53

2 Answers 2

1

In your frontend client, you cant use the fetch api or something like axios to do a GET request to obtain data from your /showPosts endpoint. Then you can display that data on the client side.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.