How to use the node-persist.create function in node-persist

To help you get started, we’ve selected a few node-persist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github covcom / 304CEM / Lab Demos / week08 / after / modules / db.js View on Github external
exports.dbConnection = function dbConnection(dbName, callback) {

	// use node-persist to connect to a "database" given by `dbName`

	const db = storage.create({dir: `./node-persist/${dbName}`})

	db.init(err => {

		if (err) {
			return callback({message: 'Unable to initialise data store'})
		} else {
			return callback(null, db)  // can now read and write to the storage file
		}

	})
}
github cliqz-oss / browser-core / platforms / node / prefs.es View on Github external
*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

import storage from 'node-persist';
import events from '../core/events';
import config from '../core/config';

export const PLATFORM_TELEMETRY_WHITELIST = [];

const prefs = config.default_prefs || {};
let started = false;

const prefsStorage = storage.create({
  dir: 'tmp/prefs',
});

// load prefs from storage
export function init() {
  if (!started) {
    prefsStorage.initSync();
    prefsStorage.forEach((key, value) => {
      prefs[key] = value;
    });
    started = true;
  }
  return Promise.resolve();
}

export function getPref(prefKey, defaultValue) {
github NP-compete / Alternate-Authentication / Home / Gdrive / getIdForDomain.js View on Github external
const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');

const nodePersist = require("node-persist");

//just replace this call with our security algorithm
var crypto = require("crypto");

const path = require('path');

const TEST_BASE_DIR = path.join(__dirname, '/gdriveCred');


storage = nodePersist.create({
        dir: TEST_BASE_DIR,
        encoding: 'utf8',            
          expiredInterval: 2 * 60 * 1000, // every 2 minutes the process will clean-up the expired cache
          // in some cases, you (or some other service) might add non-valid storage files to your
          // storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
          forgiveParseErrors: false
      });

//allow for variable storage --> security feature
storage.initSync();

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly',
  'https://www.googleapis.com/auth/drive.appdata'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
github NP-compete / Alternate-Authentication / Home / Gdrive / deleteId.js View on Github external
const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');

const nodePersist = require("node-persist");

//just replace this call with our security algorithm
var crypto = require("crypto");

const path = require('path');

const TEST_BASE_DIR = path.join(__dirname, '/gdriveCred');


storage = nodePersist.create({
        dir: TEST_BASE_DIR,
        encoding: 'utf8',            
          expiredInterval: 2 * 60 * 1000, // every 2 minutes the process will clean-up the expired cache
          // in some cases, you (or some other service) might add non-valid storage files to your
          // storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
          forgiveParseErrors: false
      });

//allow for variable storage --> security feature
storage.initSync();

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly',
  'https://www.googleapis.com/auth/drive.appdata'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
github NP-compete / Alternate-Authentication / Home / Gdrive / downloadAllDomains.js View on Github external
const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');

const nodePersist = require("node-persist");

//just replace this call with our security algorithm
var crypto = require("crypto");

const path = require('path');

const TEST_BASE_DIR = path.join(__dirname, '/gdriveCred');


storage = nodePersist.create({
        dir: TEST_BASE_DIR,
        encoding: 'utf8',            
          expiredInterval: 2 * 60 * 1000, // every 2 minutes the process will clean-up the expired cache
          // in some cases, you (or some other service) might add non-valid storage files to your
          // storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
          forgiveParseErrors: false
      });

//allow for variable storage --> security feature
storage.initSync();

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly',
  'https://www.googleapis.com/auth/drive.appdata'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
github covcom / 304CEM / Lab Demos / week08 / async / modules / db.js View on Github external
async function connect(dbName) {
    this.db = storage.create({dir: `./.node_persist/${dbName}`})
    try {
        await this.db.init()
    } catch (err) {
        console.error(err)
        throw new errors.ConnectionError()
    }
    return this
}
github hainproject / hain / app / main / shared / simple-store.js View on Github external
function createStorage(dir) {
  fse.ensureDirSync(dir);
  const localStorage = storage.create({ dir });
  localStorage.initSync();
  return localStorage;
}
github matrix-hacks / matrix-puppet-imessage / bridge.js View on Github external
let bridge;
let matrixClient;
const config = require('./config.json')
const Cli = require("matrix-appservice-bridge").Cli;
const Bridge = require("matrix-appservice-bridge").Bridge;
const AppServiceRegistration = require("matrix-appservice-bridge").AppServiceRegistration;
const iMessageSend = require('./send-message');
const nodePersist = require('node-persist');
const storage = nodePersist.create({
  dir:'persist/rooms',
  stringify: JSON.stringify,
  parse: JSON.parse,
  encoding: 'utf8',
  logging: false,
  continuous: true,
  interval: false,
  ttl: false
})
const matrixSdk = require("matrix-js-sdk");
const Promise = require('bluebird');

let lastMsgsFromMyself = [];

new Cli({
  port: config.port,
github hainproject / hain / app / main / worker / storages.js View on Github external
function createPluginLocalStorage(pluginId) {
  const localStorageDir = `${conf.LOCAL_STORAGE_DIR}/${pluginId}`;
  fse.ensureDirSync(localStorageDir);

  const localStorage = storage.create({
    dir: localStorageDir
  });
  localStorage.initSync();
  return localStorage;
}
github nfarina / homebridge / lib / server.js View on Github external
var path = require('path');
var fs = require('fs');
var uuid = require("hap-nodejs").uuid;
var accessoryStorage = require('node-persist').create();
var Bridge = require("hap-nodejs").Bridge;
var Accessory = require("hap-nodejs").Accessory;
var Service = require("hap-nodejs").Service;
var Characteristic = require("hap-nodejs").Characteristic;
var AccessoryLoader = require("hap-nodejs").AccessoryLoader;
var once = require("hap-nodejs/lib/util/once").once;
var Plugin = require('./plugin').Plugin;
var User = require('./user').User;
var API = require('./api').API;
var PlatformAccessory = require("./platformAccessory").PlatformAccessory;
var BridgeSetupManager = require("./bridgeSetupManager").BridgeSetupManager;
var log = require("./logger")._system;
var Logger = require('./logger').Logger;
var mac = require("./util/mac");
var chalk = require('chalk');
var qrcode = require('qrcode-terminal');