Storage file resets when deploying

just says there is no such file in directory: Error: ENOENT: no such file or directory, open ‘/data/datafile.db’

‘data/datafile.db’ works fine, but it does not persist with new deploy

ssh into your app and check if the /data folder exists.

these are the files and folders
:/app# ls
Dockerfile fly.toml index.html menu.html package.json style.css
app.js github_webhook.js js node_modules public tsconfig.json
favicon.ico images data package-lock.json types.d.ts

data exists, and it does not let me create /data, just says it already exitst

that’s the wrong folder, you’re in your app’s home: /app, you need to check at the root “/”

this?:

root@7815311f5170d8:/app# ls /
app bin boot dev etc home data lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@7815311f5170d8:/app# ls /data
lost+found
root@7815311f5170d8:/app#

What library are you using for your sqlite db? It looks like it’s not able to create the file. Try creating an empty datafile.db in /data

well, i did ls /data and it put me in root@7815311f5170d8:/data#. then i did touch datafile.db, then i did ls again. and now it shows:
root@7815311f5170d8:/data# ls
lost+found datafile.db

It does indeed look like it is important to your application that the file be in a place where the web server make the entire database available for download.

Try leaving in place your changes to fly.toml, but undo all other code changes. And then place code at the beginning of your application to create a symbolic link:

if (fs.existsSync("/data") && !fs.existSync("/var/www/html/datafile.db")) {
  if (!fs.existSync("/data/datafile.db")) {
    fs.closeSync(fs.openSync("/data/datafile.db", "a"))
  }

  fs.linkSync("/data/datafile.db", "/var/www/html/datafile.db")
}

Oh is that what’s happening? I assumed getdata was just an api endpoint that calls into the db… not for the user to download the .db file.

i tried what you added here, and site works, but data wipes. the getData endpoint returns the data from the db file, so i would get a list of users and can display them in a table.

Ya that’s what I thought. I didn’t know there was a use case to allow users to download the actual db file. There’s something wrong w/ your configuration somewhere, likely w/ the sqlite db library.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.