loading...

re: How can I read a local JSON file in HTML/JavaScript? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Option 1: Use localStorage as a Database function setData (itemName, itemValue) { let databaseString = localStorage.getItem("an-awesome-local...
 

Oh, I just thought of one more idea!

fswatch -o . | xargs -n1 -I "{}" aws s3 cp data.json s3://your-s3-bucket-name

This will watch the current directory (using fswatch) and then run the aws s3 cp command to upload the data.json file to an s3 bucket called your-s3-bucket-name.

Now you have a single command that will watch your file for changes and keep it in sync with a file at a url (something like "your-s3-bucket-name.s3.amazonaws.c...) that's publicly accessible and can be loaded into any app.

This might seem like a pain to set up (install fswatch, install the aws CLI, configure the aws CLI with your credentials, and then set up an s3 bucket that's public by default), but once it's done, it's a dream to work with!

All of a sudden you have this really easy way to sync local files to remote files whenever they change — and that's incredibly powerful. You can use this with CSS files to update a live website's styles, JS files to change a live prototype's behavior, or just use it to load JSON into a prototype app, like you're doing. It'd definitely a cool thing to have in your tool belt.

P.S. I'm not an expert at fswatch, so don't ask me what that weird | xargs -n1 -I "{}" part of the command does. All I know is it'll run the command after it every time a file in the current directory changes...

code of conduct - report abuse