DEV Community


Where do you store your apps flat file databases?

imthedeveloper profile image ImTheDeveloper ・1 min read

Hi All,

I've built a small node.js application which uses a local JSON file to persist data across restarts (nedb npm package for reference). I currently have this file set in my .gitignore and it is simply held within a Database folder in my project.

I'm using ansible to deploy my program to my production server, which will pull down the latest remote git repo and run the install/build and startup. I'm starting to wonder however where a sensible place would be to store the JSON file that is created upon first start up of the application.

Does storing it WITHIN the project folders make sense? I have noticed a few developers, especially on ubuntu save it to the users home directory and sometimes even as a hidden folder e.g. /home/user/.app/database.json

What is best practice in this case? My only worry is that potentially that project folder could get deleted, for whatever reason maybe to do a complete fresh install, but I would always like to keep the database file intact.

Happy for thoughts and discussions on this as I think people tend to do this in lots of different ways.

Discussion (2)

Editor guide
dmerand profile image
Donald Merand

Capistrano deployments with Rails have some good defaults - the app is always deployed into a timestamped folder that's sym-linked to a "current" folder. Shared resources like databases, file storage, are put into a top-level folder that's not (typically) overwritten on commit. So...

# Commit files to here...

# Symlink these files, which are what gets served.
/project/current -> /project/versions/20180318
/project/current/database.json -> /project/shared/database.json

That approach works decently well to keep things separated without being too confusing.

coolgoose profile image
Alexandru Bucur

If we're talking about a linux script in particular, I'd recommend following the XDG spec and having it in $XDG_DATA_HOME/app_name/db.json