Noob Storage Question

Hi I am creating a super simple app for my parents and I’m quite new to this. I am only experienced in Mat lab and a little C. Anyways I am basically modifying the tutorial hikr app and I want the changes to be persistent, how do I accomplish that? I dont want to run it on a backend server, just local data persistence. It’ll only be text and maybe a photo in the future so there is no concern for storage space limitation.

Any help would be great thanks!

Hi Isaac,

you should take a look at FileSystem module. I suggest storing data in JSON format.

Hope this helps!

I have been looking through there but I am unsure how to implement it. If I was to literally use this for the backend on the hikr tutorial, how would I save variable values there to then be called on later?

The example on that page I linked shows how to use it for both writing and reading a file. What’s the issue?

There is also an example for using Storage library, which you could easily change to use FileSystem instead. Hope this helps!

Thank you for the help! I am confused where I should implement this function, do I use it in the Backend.js? or on the actual Pages where variables are being written/read? Does this create a file or does the associated file need to be created before hand and exported with the app?

This is my first app so I am REALLY new to this.

Than you again for the help you’ve already given to me. I am going to try to implement in the Backend.js file and work from there

In the case of hikr example, it might indeed be best to implement a FileSystem abstraction in Backend.js, since that’s your model where the data resides. The pages should only be viewmodels that transpose the data from model to view, and do not care about where the data ends up being stored, or how it looks like on the screen.

However, if you’re REALLY new to making apps or coding in general, you should probably follow the Tutorial very carefully and maybe learn some JavaScript on the side.

The FileSystem.writeTextToFile() function creates the file if it doesn’t exist, but you also have other functions, such as exists() that you can use, depending on what you need to achieve. See the FileSystem Interface for details.

This has helped immensely thank you!

Okay I implemented this strategy but the data entered in the app is not persistent still. I think it may be because my variable ‘pinfos’ and ‘vehicles’ are not observable? Also I came across this out discussion - - could that have something to do with my problem?

My thought process is that on start-up the variables recieve their values that i have given. Then a storage file is read and if there is data within it the variables are changed to what is stored. If no storage file is found, one is created and the variables (with default values) are stored in the file. When the variables are updated by the user, the functions updateVehicles and updatePinfos will write the new values of the variables to the storage file. Does this flow not work or is my code not accomplishing the steps in the correct order? Fuse is not giving me any error codes.

Here is the link to my current project on github