How to use the node-persist.init 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 funsocietyirc / MrNodeBot / bot.js View on Github external
async _initStorageSubSystem() {
        await storage.init();
        try {
            const tmpIgnore = await storage.getItem('ignored');
            this.Ignore = tmpIgnore || this.Ignore;
            const tmpAdmins = await storage.getItem('admins');
            if (tmpAdmins) {
                this.Admins = tmpAdmins;
            } else {
                this.Admins = [_.toLower(this.Config.owner.nick)];
                await storage.setItem('admins', this.Admins);
            }
        } catch (err) {
            logger.error('Error Loading the Persisted Assets'); // TODO Localize
            return;
        }
        logger.info(t('storage.initialized'));
    }
github xyfir / accownt / server / lib / register / finish.ts View on Github external
export async function finishRegistration(jwt?: Accownt.JWT): Promise {
  if (jwt === null) throw 'Invalid or expired token';

  // Verify JWT's userId matches the userId that the JWT's email points to
  // This way only the most recent email verification JWT is valid since it
  // will point to the newest user
  const userId = await emailToId(jwt.email);
  if (userId != jwt.userId)
    throw 'This token has been invalidated by a newer one';

  // Verify user's email
  await storage.init(STORAGE);
  const user: Accownt.User = await storage.getItem(`user-${jwt.userId}`);
  user.verified = true;
  await storage.setItem(`user-${jwt.userId}`, user);

  return await signJWT(jwt.userId, jwt.email, JWT_EXPIRES_IN);
}
github gpmer / gpm.js / app / registry.ts View on Github external
async init() {
    await storage.init({
      dir: config.paths.storage,
      stringify: JSON.stringify,
      parse: JSON.parse,
      encoding: 'utf8',
      logging: false, // can also be custom logging function
      continuous: true, // continously persist to disk
      interval: false, // milliseconds, persist to disk on an interval
      ttl: false, // ttl* [NEW], can be true for 24h default or a number in MILLISECONDS
      expiredInterval: 7 * 24 * 3600 * 1000, // clear cache in 7 days
      // 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 // [NEW]
    });

    this.repositories = (await storage.getItem(this.key)) || [];
  }
github OfficeDev / Office-Add-in-NodeJS-SSO / Before / src / server-storage.ts View on Github external
public static async persist(key: string, data: any) {
        await storage.init();
        await storage.setItem(key, data);
        console.log(key);
        console.log(data);
    }
github habitlab / habitlab / webpack_habitlab_component_rename_plugin.js View on Github external
async function get_storage() {
  if (cached_storage != null) {
    return cached_storage
  }
  const storage = require('node-persist')

  await storage.init()

  //await storage.clear()
  cached_storage = storage
  return storage
}
github istvanmakary / react-debugger-server / src / index.ts View on Github external
async setupStore() {
    await storage.init({
      dir: 'store',
      expiredInterval: 7200000,
    });
  }
github roblox-ts / roblox-ts / src / analytics.ts View on Github external
async function getStorage() {
	if (!storageInitialized) {
		await _storage.init({
			dir: path.join(os.homedir(), ".roblox-ts"),
		});
		storageInitialized = true;
	}
	return _storage;
}
github quicktype / quicktype-vscode / src / extension.ts View on Github external
vscode.commands.registerTextEditorCommand(Command.PasteTypeScriptAsTypesAndSerialization, editor =>
            pasteAsTypes(editor, "typescript", false)
        ),
        vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForJSON, editor =>
            openForEditor(editor, "json")
        ),
        vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForJSONSchema, editor =>
            openForEditor(editor, "schema")
        ),
        vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForTypeScript, editor =>
            openForEditor(editor, "typescript")
        ),
        vscode.commands.registerCommand(Command.ChangeTargetLanguage, changeTargetLanguage)
    );

    await persist.init({ dir: path.join(homedir(), ".quicktype-vscode") });

    const maybeName = await persist.getItem(lastTargetLanguageUsedKey);
    if (typeof maybeName === "string") {
        explicitlySetTargetLanguage = languageNamed(maybeName);
    }
}
github OfficeDev / Office-Add-in-NodeJS-SSO / Before / src / server-storage.ts View on Github external
public static async clear() {
        await storage.init();
        await storage.clear();
    }
}