A Persistent Filesystem Solution for Repl.it
h
MrEconomical (2225)

Keep your files persistent

A persistent filesystem on repl.it is something I have wanted to see for a very, very long time. But unfortunately it isn't going to be added, which means that any programatic changes to files you make when you are offline will not be saved. This makes keeping logs or storing data within files difficult on repl.it

The team has introduced repl.it DB, a simple key-value storage built into your repls, to solve this issue. However, repl.it db isn't a perfect solution as it can't replace something like SQL or SQLite databases, and also your code will only ever work on repl.it.

That's why I've made this simple workaround, a script that saves your files into repl.it db. How the repl.it file system works is that any programatic changes will remain on the repl while it is running, but when it restarts from time to time and you aren't on it the changes will be lost. This script detects when files are changed, saves them into repl.it db, and when your repl restarts the script will fetch the changes and then replace your files. Additionally, the state management system using a checksum lets you edit your files as normal when your repl is not running and your manual changes will not be replaced by the old version stored in repl.it db.

I tried to make this script as efficient as possible, completely asynchronous to be non-blocking, and also added string compressing to save space within repl.it db as you only get 50 MB to work with. Every time the repl is run I also delete any files you don't want to keep persistant anymore from the database so you don't have to worry about any data being stuck in there and counting towards the data limit.

Using the script is very simple. All you need to do is include it into your program and run it at the very top. The function takes an array of all the files you want to keep persistent. You can also see the repl attached for an example.

One thing to note is that if you read any files at the beginning that haven't been replaced yet, the old version of the file without changes will still be there so you need to wait until the function is done. (If repl.it ever updates their node version we can use top level await and get rid of the ugly function thing)

You are viewing a single comment. View All
MrEconomical (2225)

@Coder100 http.request gang rise up