Home > Enterprise >  Where does Deno keep the `localStorage` SQLite file?
Where does Deno keep the `localStorage` SQLite file?

Time:10-08

I've just read through the Web API's from the Deno docs and seems like localStorage is implemented as a persisted SQLite and sessionStorage is implemented as a in-memory SQLite.

Whenever passing no --location argument, where in my filesystem can I find the SQLite DB?

CodePudding user response:

According to Environment variables | Set Up Your Environment | Manual | Deno, this information is stored in DENO_DIR:

  • DENO_DIR - this will set the directory where cached information from the CLI is stored. This includes items like cached remote modules, cached transpiled modules, language server cache information and persisted data from local storage. This defaults to the operating systems default cache location and then under the deno path.

The default directory is:

  • On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
  • On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
  • On macOS: $HOME/Library/Caches/deno
  • If something fails, it falls back to $HOME/.deno

CodePudding user response:

By running deno info you get the value for Origin storage, which is where localStorage data is saved. (See Where can I see deno downloaded packages? for more info)

$ deno info
DENO_DIR location: /home/foo/.cache/deno
Remote modules cache: /home/foo/.cache/deno/deps
npm modules cache: /home/foo/.cache/deno/npm
Emitted modules cache: /home/foo/.cache/deno/gen
Language server registries cache: /home/foo/.cache/deno/registries
Origin storage: /home/foo/.cache/deno/location_data

Inside .cache/deno/location_data you'll see different folders for different storages depending on the --location flag.


Run the following Deno script:

localStorage.setItem("myDemo", "Deno App");

Now you'll see a folder inside location_data

# Replace with the location specified in <Origin Storage>
ls ~/.cache/deno/location_data/

You'll get something like this:

03c0fe5beae8096bc7bdbe2232281947d85e38f4f95f6397559f30b670cb8549/

If you enter that folder you'll get three files:

local_storage  local_storage-shm  local_storage-wal

You can load local_storage file into sqlite3 and see the data:

# inside that folder
sqlite3 local_storage
select * from data;

The output will be the data saved by setItem

myDemo|Deno App

Have in mind that this is for internal use

  • Related