The serializer to add. Must implement the ISerializer interface.
import { Config, ISerializer } from 'node-json-db';
const urlSerializer: ISerializer = {
type: "URL",
serialize: (value: URL) => value.href,
deserialize: (value: string) => new URL(value),
test: (value: any) => value instanceof URL,
};
const config = new Config('mydb');
config.addSerializer(urlSerializer);
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.
The encryption key. Must be exactly 32 bytes. Can be:
Add a custom serializer for handling additional types during JSON serialization.
Custom serializers allow you to extend the built-in type support (Date, Set, Map, RegExp, BigInt) with your own types. Each serializer uses a
__type/__valueenvelope pattern in the stored JSON.