DEV Community

ImTheDeveloper
ImTheDeveloper

Posted on

Where do you store your apps flat file databases?

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.

Top comments (2)

Collapse
 
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...
/project/versions/20180318/yer-source
/project/shared/database.json

# 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.

Collapse
 
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

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay