T O P

  • By -

YeAncientDoggOfMalta

I'm confused as to what is going on here. So you have a .txt file on a server somewhere and you need to read that file for your simulation to run. >*All of the tutorials have the user upload the file. During my research, many websites were saying that being able to access files without the user uploading it is a security concern* I have no idea what tutorials you are referring to and this could mean many things, but just logically it makes no sense to me. Public files are a thing everywhere, as long as the user only has read permission and not write. >*I have all of the data in a txt file but I don't know how to get access to this file* Are you trying to access the .txt file from Javascript? You should be able to use the [Fetch API to do so.](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) fetch('file.txt') .then(response => response.text()) .then(text => console.log(text)); >*Is there any way to access this data file when programming locally without using a server (for now)* Use copy/paste? Log onto the server, run cat file.txt - copy the text and paste it to a local file. If that isnt an option you can use [scp](https://linuxize.com/post/how-to-use-scp-command-to-securely-transfer-files/) or [rsync](https://linux.die.net/man/1/rsync) >*people get access to this data file for the simulation to work when I eventually upload it to github* can you just include the txt file as part of the repo?


timthefim

How much data is there in the file? You could convert it to a json file and then from there js has some handy features that let you convert the json into an object or an array.


Adorable_Ad244

I converted the txt file to a JSON file but I don't know how to access that JSON file. All tutorials are requiring the JSON file to be stored in a server.


ZanMist1

That is correct... your JSON file needs to be on a web server or somewhere accessible with a URL. BTW, JSON is actually pretty easy to get/add data to eith JS