So I am working on a webpage (hosted on github pages) where I need to convert the data entered by the user to a json object and then saving it to a file on the github repo for later use.
So far, I've converted the data to a json object, but I'm facing difficulty in storing this object to a .json file in my github repository.
Any suggestions on this would be appreciated.
Cheers.
As MAttds17 said you will need a server side.
If your code will be simple, you can use a Backend as a service like Firebase or Backand.
If you think you will have heavy logic in your server side, you can host a real application in Heroku or another alternative.
Related
i have written a game in javascript with the p5.js library. Now i want to host the game on a server to conduct a survey on a service like amazon turk. Ideally the clients recieve a URL to the game and play it while in-game actions are tracked and stored in node.js or on the server and exported as a .csv file once they are done playing. After they finish the game the csv. file should be sent automatically to a location that i can then access. I have zero experience in server hosting or similar topics.
So a couple questions arise:
Is a hosting service like Heroku suitable for hosting the game?
Do i need to use node.js to make this happen?
Which of those two would extract the data and store it to a csv? And where is the file stored?
How do i get or access the csv. after?
Any alternative takes to solve the problem?
Thanks alot in advance!
github repository: https://github.com/luuuucaaa/schaeffers-charade
game on github pages: https://luuuucaaa.github.io/schaeffers-charade/
If I were you, I would do it like below:
Host
Since your project is basically a html & JavaScript static contents,
AWS S3's static hosting would be sufficient (Also, the current git hub pages is another option if you just want to host it).
Hosting on node.js environment is also available using webpack serving, but it requires additional works. (but if you require other npm packages to generate .csv file, you need webpack anyway to bundle js file and attach it to html)
Data Storing
Two ways are considerable,
the first is to store it on the filesystem. Generate .csv via JS script within your app, and save it where the app is hosted (if you go with s3, you can access it afterwards, but I'm not sure if it can write objects by script)
The second is to post the data to another API endpoint. (for example building an API Gateway on AWS that triggers Lambda, which stores it on S3)
It's merely an example and I don't know exactly what you want to achieve, but take it into considerations. Good luck. Cool game BTW.
I need reflection, vision and documentation on my problem.
I wrote a python script to calculate something from an API and export the result in a CSV file. Then, I use a JavaScript script to display the data from this CSV file on a building website.
I need to have the latest data available for my website, so I opened a VM instance in Google Cloud Platform (Google Compute Engine) and set a Crontab job to run automatically my python script. The calculation is now executed every day and the result is exported to the CSV file, but stored in this VM instance.
Here is my goal: How can I get my CSV file on my website? The CSV is always on the virtual machine and I do not know how to communicate with my JavaScript script to the VM. Do I have to communicate directly with the VM? Do I have to go through another step before (server, API, etc.)?
I cannot find a specific solution for my problem on the internet.
Thanks in advance.
How can I get my CSV file on my website?
By making your python script output the CSV into your website's root folder.
Example, if you're running apache, chances are your root folder is somewhere in /var/www/html/...
If the script is generated from another machine (not the one with your website), then I would host it and make the server hosting your website fetch it via cronjob.
Basically:
If your CSV is generated from the same machine as the website that will use it - simply output it to the website's folder
If your CSV is generated from another machine, make it publicly accessible and have your website's machine cronjob fetch that CSV a few minute after it's generated.
I would suggest you a different approach than using a VM for calculating and storing your CSV.
The idea would be using a Python Cloud Function instead, that will be run by Cloud Scheduler and Pub/Sub.
This function will generate your CSV file, that will be stored on Cloud Storage. Here you can find an example of how to upload an object to Cloud Storage using Python.
Then, you need to give your website the ability to access that CSV file in Cloud Storage when required. As indicated by #guillaumeblaquiere, the exact way will be dependent on where your website is hosted: especially, it will constraint the auth mechanisms that you need to use to download your data. The documentation in GCP provides several examples about this matter.
The documentation of Google Cloud provides an example of the proposed architecture.
I came across an article that, in a certain way, describes the setup I suggested as well.
Please, consider review the costs of the different mentioned products.
Most of my experience with database manipulation has been through node.js, and writing simple APIs for class. I'm now trying a private project, where I would write a database, and read in information from it to display on a website hosted through github. however, for what I'm doing, an API seems unnecessary, as I should be able to upload the database file onto github, and have the website read from that, rather than hosting a node.js server. So, what I'm asking is at a high level, how would I get information from a database into a form I can read onto a website, and would just creating a json locally, or storing the info some other way, be a better solution?
If the database is very large, then this really should be done server side.
If the database is small, one option is to convert the sqlLite database to JSON, and then just use fetch to grab, and just parse using Javascript.
But another option I think you might like, is use a sqLite client compiled for the browser. If your browser is relatively new and supports webAssembly you might find this interesting.
https://github.com/sql-js/sql.js
Basically sqLite compiled for the browser..
One issue with any of these is security, anybody could of course download the JSON or Sqlite database in full and have full access. Server side you can implement user authentication etc.
Recently, I found that there is called 'LowDB' and it can control the json file with NodeJS.
Actually, I can use MySQL or other databases but I think the App that I developing now is small application so it needs very tiny DB like simple Json.
This Link is connected to lowDB example.
Link
https://github.com/typicode/lowdb
As you can see it controls json file and it includes CRUD(Create, Read, Update, Delete) function. But the data are save in Local storage not in server. So Even I control the json files it will only apply in Local Json file. I want to save it in server.
How can I manage json file with NodeJS? Please give me some keywords or introduce some Node Dependencies.
I'm stumped. So I've written a nice little web app that gets all its data from a JSON that has one array in it. To bridge the AngularJS-parts and the data, I have this line in my services.js
.constant("baseURL","http://localhost:3000/")
This of course only works with me locally. But I haven't considered that I might have to get my web host to serve up the data.
Now, I'm a complete beginner at this. I've managed to code my app with moderate effort, having only started coding in January. So I'm completely out of my league here. I don't even know what I'm looking for. I mean, I have to replace the localhost:3000with something. But if I do http://domain.com/db.json that obviously doesn't work.
I've talked to Godaddy's tech support and they go "Nuh-uh, not helping" the second I show them this line of code. Because, to be honest, I don't even know what the address I'm looking for is called. Is it a URI?
I have a few questions regarding this and I turn to you, because - this story gets worse - there's a possible job on the line for me. Not a coding thing, but the data that is parsed from the JSON into the site.
What is the address I'm looking for called?
How do I get my hosting to serve up JSON data? I mean, I don't even know what I need to ask the tech support people here. Do I need a JSON server?
If they don't offer it, where could I get my JSON data served in a way that I can push more articles into the array and preferrably edit it, too?
Thank you so much!
EDIT #1
If it helps, here's the contents of my /webroot/personalfolder
You will need to change your localhost:8000 to your domain name. For example, if you bought www.foobar.com then your base URL would just become www.foobar.com On a rented web server (like GoDaddy Hosting) ports 80 and 443 are normally open so you wouldn't need to specify this. If you are self hosting, you will need to open these ports on your router and apply port forwarding rules to your PC.
When you host your published website, you will just put your JSON file in with your Website Source. For example your structure may look like this:
AngularAppFolder/index.html
js
csss
Just add another folder called db place your JSON file in there, and reference it in your Angular code, no need to worry, its just another file just like your HTML or CSS which makes up your website. Remember though that your JSON data will be publicly available here!
If your looking for an alternative way of getting your JSON data, you may want to look into creating a REST API. This uses a web server to dish out data depenant on the HTTP request you send to it. but that's a very big topic! Here is some reading into it if your feeling brave! Node.js REST API tutorial
Final note: if you are self-hosting this application (running it on your own computer or server) then you will need to change the DNS record for your domain name to the global IP address of the server! you shouldn't have to worry if your using the hosting offerings from a company such as GoDaddy however.
You need to change the baseURL value to whatever the URL on which the site is hosted. Something like http://<mysite>.com.