+ 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!

15th Jul 2019, 1:09 PM
Stan Berger
Stan Berger - avatar
14 Answers
+ 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")
6th Nov 2019, 4:25 PM
Calviղ
Calviղ - avatar
+ 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.
6th Nov 2019, 6:35 PM
David Carroll
David Carroll - avatar
+ 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
2nd Nov 2019, 10:53 AM
Calviղ
Calviղ - avatar
+ 4
Stan Berger json server accepts post request too. Check out this code https://code.sololearn.com/Wj7yW7R4iSId/?ref=app
2nd Nov 2019, 1:42 PM
Calviղ
Calviղ - avatar
+ 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
2nd Nov 2019, 9:49 PM
Adi Pratama
Adi Pratama - avatar
+ 4
Adi Pratama-Universitas Brawijaya json_server allows us to read/write the server json file, please check out my code i shared previously.
3rd Nov 2019, 12:09 AM
Calviղ
Calviղ - avatar
+ 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!!
6th Nov 2019, 7:23 PM
Lisa F
Lisa F - avatar
+ 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.
6th Nov 2019, 3:05 PM
David Carroll
David Carroll - avatar
+ 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.
6th Nov 2019, 4:47 PM
Calviղ
Calviղ - avatar
+ 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???
1st Nov 2019, 10:32 PM
Lisa F
Lisa F - avatar
+ 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.
2nd Nov 2019, 12:05 PM
Stan Berger
Stan Berger - avatar
+ 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
6th Nov 2019, 2:34 PM
Lisa F
Lisa F - avatar
+ 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. 😉
6th Nov 2019, 8:20 PM
David Carroll
David Carroll - avatar
+ 1
David Carroll understand....was adding a new wrinkle to the question
6th Nov 2019, 4:26 PM
Lisa F
Lisa F - avatar