+ 4
Exchanging Files with Server
Is there a simple was to create a table in HTML that is manipulated by Javascript and upload and retrieve that table to and from a database using NodeJS? Or is it done easier just using what's basically available from GoDaddy, Wix.com, etc.? Or is PHP and mySQL easier? As a beginner, I just want to play with the server side!
14 Antworten
+ 5
Lisa F you could use mysql npm package with node, to retrieve mysql data and convert it into JSON.
Here is the sample code, you can use.
https://glitch.com/edit/#!/mysql-to-json
The result of the console log would display the json string (Select "Tools" followed by "Logs")
+ 5
Lisa F Ah... I thought you thought his data was stored in MySQL and wanted to know how he converted it to JSON. 🤦♂️
Instead... you were just generally asking about how to convert data stored in MySQL into JSON that gets sent to the browser. 😉
In that case, there are many ways to manage this with all sorts of pros and cons.
The conventional approach is to load the data into an object model on the server. There are a number of ways this can be done as well... each with advantages and disadvantages.
The specific method will depend on the language, platform, frameworks in use, etc.
Let's assume you are using some ORM, which is a library for loading data from a database into some object model you can interact with in code.
This object model could then be used directly or it could be used to create another object matching the expected JSON structure. Either way, a JSON library or builtin functions (depending on the language and platform) will be used to serialize the object into a JSON string.
+ 4
Stan Berger you could use json server to build rest api. And use Axios to fetch the api from frontend and populate the data on a table.
Here a sample code built from json server and Sololearn code as frontend web access.
https://glitch.com/~slloves
https://code.sololearn.com/W3Qe5hqksyLe/?ref=app
+ 4
Stan Berger json server accepts post request too. Check out this code
https://code.sololearn.com/Wj7yW7R4iSId/?ref=app
+ 4
So, instead using PHP and mySql to update the data,
We should use Js and JSON which only can store the data and create the table but can't update the database.
This question post also asking about how to upload or update the database
+ 4
Adi Pratama-Universitas Brawijaya json_server allows us to read/write the server json file, please check out my code i shared previously.
+ 4
ty David Carroll and yes your answer really helps. concepts are the hardest questions to ask about but until you wrap your head around the big picture the details don't really make sense. ty
I personally can't imagine life without needing to involve a relational database somewhere in the application but am starting to appreciate nosql databases too ....so just starting to figure out how that all mixes together in one app.
so here's another basic question...what are the key characteristics of data that tells you that it doesn't need to be stored in a relational database?? again ty!!
+ 3
Lisa F I don't believe he's using a relational database. Based on his previous comments, he's working against a JSON file on the server.
+ 3
David Carroll is right, the previous code was based on a json file, json server compiles the json file into internal db as init data whenever it changes.
+ 2
I think this is a great question but it covers sooo many areas folks maybe decided not to answer. break it down and you'll get responses. what exactly do you want to do? exchange files? or build a data driven app where users can both select and update data in a database???
+ 2
Thank you both, Lisa and Calvin! Yes, I would like to learn how build my own data driven app where users can both select and update data in a database. Calvin, I like your solution for creating a table using JSON objects.
+ 2
Calviղ ty for sharing your knowledge so freely! if some of your data is stored in a relational database such as mysql how do you recommend getting it into a json format? i guess I don't know where SQL fits into this. tytyty
+ 2
Lisa F I love this follow up question.
So we don't completely hijack this question, post this as a new question and tag me there. I'll respond when I get a free moment. 😉
+ 1
David Carroll understand....was adding a new wrinkle to the question