node-json-db
    Preparing search index...

    Implements

    Index

    Constructors

    • Parameters

      • filename: string
      • saveOnPush: boolean = true
      • humanReadable: boolean = false
      • separator: string = '/'
      • syncOnSave: boolean = false

      Returns Config

    Properties

    adapter: IAdapter<any>
    humanReadable: boolean
    saveOnPush: boolean
    separator: string
    syncOnSave: boolean

    Accessors

    Methods

    • Enable encryption for the database using AES-256-GCM.

      When encryption is enabled, the database filename automatically changes to use the .enc.json extension. For example, mydb.json becomes mydb.enc.json. This prevents accidentally accessing encrypted databases without proper encryption settings.

      This method is idempotent - calling it multiple times won't keep changing the filename.

      Parameters

      • cipherKey: CipherKey

        The encryption key. Must be exactly 32 bytes. Can be:

        • A string of 32 characters
        • A Buffer of 32 bytes
        • A symmetric KeyObject with 256-bit key size (from Node.js crypto module)

      Returns void

      If the key is asymmetric (not supported)

      If the key length is not exactly 32 bytes

      import { Config } from 'node-json-db';
      import { randomBytes } from 'crypto';

      const config = new Config('mydb', true);
      const key = randomBytes(32); // 32-byte encryption key
      config.setEncryption(key);
      // Database will now be stored in 'mydb.enc.json' with encrypted data