Where to store data permanently


#1

Hey there guys,

I’m currently working on my first Atom package and I stumbled over a problem. For my package I need to store data permanently somewhere. I heard about the ~/.atom folder to store somewhat but since Atom is multi-platform, how could I properly retrieve this directory? Or where should i store stuff to make it working across all OS?
Creating a directory object with ~/.atom given as path results in a zero length object what could not be if it worked out since this directory exists and is the total opposite of empty.

Thanks in advance,
Max


#2

[quote=“mcstreetguy, post:1, topic:44406”]
I heard about the ~/.atom folder to store somewhat but since Atom is multi-platform, how could I properly retrieve this directory?[/quote]

I’m not sure whether this is the best way to retrieve the location of .atom, but I’ve used this in the past:

import { dirname } from 'path';

const configPath = atom.config.getUserConfigPath();
const atomDir = dirname(configPath);

As far as I know, the .atom/storage is meant to store things.

For package settings and the likes, I personally prefer using the Storage interface, since it should be much faster.


#3

Example benchmarks to back this up:

// localStorage is synchronous, so let's use readFileSync
// for a “fair” comparison
import { readFileSync } from 'fs';

console.time('Read from file-system');
readFileSync(atomPath + '/storage/example.json');
console.timeEnd('Read from file-system');
//-> Read from file-system: 0.278ms

console.time('Read from localStorage');
localStorage.getItem('example.item');
console.timeEnd('Read from localStorage')
//-> Read from localStorage: 0.025ms

#4

My first idea was to use the fileystem since I developed some electron projects before.
But I didn’t new about the Storage Interface as you mentioned.
I’ll take a closer look at that
Thanks a lot by now :slight_smile: