Save server variables when projects go to sleep?

Minor question; is it possible to save a variable in a server.js file so that it doesn’t get reset when the project wakes from sleep?
On a related note, if this isn’t possible, is there a better approach to storing some data on the server that needs to be read from and written to pretty often?

Yes, usually this is done by serializing the variable to a string, then writing to a file mydata.txt . A nice representation in string form is JSON, and you can use node’s fs package to write to mydata.json.

You likely want to catch the process terminate signal to know when to write the file :slight_smile:

A database is suited to this situation, different items of data can be read and written to at different times. There are a lot of database engines available in npm. There are plenty of sample scripts in glitch as well, some in Glitch: The friendly community where everyone builds the web

A recent lengthy conversation on this is here: My JSON files keeps breaking when writing for some reason