robokitty icon indicating copy to clipboard operation
robokitty copied to clipboard

Store Scheduled Setting better

Open rachelnicole opened this issue 10 years ago • 4 comments

Maybe localStorage or implement a simple DB system.

rachelnicole avatar Nov 28 '15 19:11 rachelnicole

It's simple enough to store it in a file unless you really need something more complicated.

lee-dohm avatar Nov 28 '15 20:11 lee-dohm

@lee-dohm could you point me to a resource so I can read up on how to do this? I never deal with having to store anything usually / someone else does backend management for me so storing data is new to me. :)

rachelnicole avatar Nov 28 '15 20:11 rachelnicole

@rachelnicole you might have a look at level or PouchDB. PouchDB is pretty awesome since you can use it on the front end (using whatever your browser supports) or on the backend (it actually uses level behind the scenes there)

toddself avatar Nov 28 '15 22:11 toddself

@rachelnicole Sure thing! You're already using the required library on line 3. You can do this:

var fs = require('fs'),
    path = require('path'),
    process = require('process');

// Modify where the file is stored to taste
var configFile = path.join(process.env.HOME, 'feeding-interval.txt');

function retrieveInterval() {
  return fs.readFileSync(configFile);
}

function storeInterval(interval) {
  fs.writeFileSync(configFile, interval);
}

lee-dohm avatar Nov 29 '15 02:11 lee-dohm